Hi list

I have wirtten the following perl code which has some configuration
params such as prefix,suffix,midfix and nofix. The logic is filenames
will be selected based on prefix,suffix and midfix pattern.After the
fiter through above 3 patterns if file names exists with nofix
patterns it will be removed from the final list.

use strict;
use warnings;

#my $pfx ="CAT";
my $pfx = '';
my $sfx = '.Z' ;
my $mfx =   'r';
my $nfx= "dmp.Z,Q.Z,dat.Z,ctl.Z,A.Z";
my @fnames = 
("CAT_arcdf231456_dmp.Z","ABCD_1234.txt","FILE_STAT.Z","CAT_qwerty.Z");

my($re_pfx,$re_sfx,$re_mfx,$re_nfx);
my(@pre_fix,@sfx_fix,@mid_fix,@not_fix);

if((length($pfx)) > 0 and $pfx !~ /^\s+$/) {
        @pre_fix = split(/,/,$pfx);
        #find_largest_element(@pre_fix);
        $re_pfx  = join "|",@pre_fix;
        $re_pfx = qr/$re_pfx/;
}
if((length($sfx)) > 0 and $sfx !~ /^\s+$/) {
        @sfx_fix = split(/,/,$sfx);
        $re_sfx  = join "|",@sfx_fix;
        $re_sfx = qr/$re_sfx/;
}

if((length($mfx)) > 0 and $mfx !~ /^\s+$/) {
        @mid_fix = split(/,/,$mfx);
        $re_mfx  = join "|",@mid_fix;
        $re_mfx = qr/$re_mfx/;
}


if((length($nfx)) > 0 and $nfx !~ /^\s+$/) {
        @not_fix = split(/,/,$nfx);
        $re_nfx   = join "|", @not_fix;
        $re_nfx      = qr/$re_nfx/;
}
my @listed;

foreach my $fname(@fnames) {
                        if($fname =~ /^.*?$re_nfx$/) {
                                #print "FILE NAME [$fname] is not a valid file 
\n";
                                next;
                        }elsif ($fname =~ /^$re_pfx/){
                                push(@listed,$fname);
                        }elsif ($fname =~ /^.*$re_sfx$/) {
                                push(@listed,$fname);
                        }elsif ($fname =~ /^.*$re_mfx.*$/) {
                                 push(@listed,$fname);
                        }elsif() {
                                 push(@listed,$fname);
                        }else {
                                  push(@listed,$fname);
                        }
                        
}


for(@listed) {
        print $_,"\n";
}

prefix,suffix and midfix can be defined and can not be.
So in the above scenario file ABCD_1234.txt should not be selected
because it is not matching $sfx but I m not able to filter this.

Thanks & Regards in advance
Anirban Adhikary.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to