need some help excluding with file::find::rule

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
(I think I may have posted this msg in the wrong group before, so my
apologies for a double post, i believe this is the right place)


First please forgive me if this is the wrong way to go about asking
this question.

I have a script im working on that is looking to only get the
filenames with ".mw.|.cw.|.uw." and exclude any filenames (which
happen to be FQDNs of servers) that do not have that criteria

the structure to search is /data*/backups/$server/daily.0/$server
(where $server would have the .mw.|.cw.|.uw. characteristic)

this is what I have thus far, I dont feel this is the fastest way to
go about doing this (im not sure), I also want to make sure to exclude
and not even "parse" any dirs that dont have the afore mentioned

any feedback is appreciated



use strict;
use warnings;
use File::Find::Rule;
use File::Basename qw/basename dirname/;

my @data_dir =
  qw { /data/backups };    # list here the data dir if you want to
loop on it.
foreach my $dir (@data_dir) {
print "looking at $dir..\n";
    my ( $bkpcount, $dbcount ) = 0;    # db and backup file counter

    # Gather server name with .mw, .cw, .uw on fqdn
 my %server_w_log;
# This part will search for every  directory with .mw, .uw. cw and
take the base name as key to hash
    opendir( DIR, $dir ) or warn "can't open $dir\n";
    my @servers = readdir(DIR);
    foreach my $server (@servers) {
        next if $server =~ m/^\./;
        %server_w_log =
          map { my $tempfile = basename $_; $tempfile => $_ }

print "server is $server..\n";


(there's more to the script but this is the first part that's giving
me problems.

any help is greatly appreciated.

Re: need some help excluding with file::find::rule

solaristar wrote:
Quoted text here. Click to load it

It looks like you could use a file glob to get the list of file names
you need, for example (UNTESTED):

my $server = '.[cmu]w';

my @files = glob "/data*/backups/$server/daily.0/*$server";

Quoted text here. Click to load it

That is the same as saying:

       my $bkpcount = 0;
       my $dbcount;

If you want both variables initialized to 0 then you have to assign to both:

      my ( $bkpcount, $dbcount ) = ( 0, 0 );


      my ( $bkpcount, $dbcount ) = ( 0 ) x 2;


      my $bkpcount = my $dbcount = 0;

Quoted text here. Click to load it

You should include the $! variable in the error message so you know why
opendir() failed.

Quoted text here. Click to load it

Even though opendir() failed you are still trying to read from the
invalid directory handle?

Quoted text here. Click to load it

The '.*' at the beginning and end are superfluous, it should be just
qr/\.(mw|uw|cw)/, or even better qr/\.[muc]w/.

Quoted text here. Click to load it

The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

Site Timeline