basheer has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have to read the directory and fetch the txt file and match the name (partial_pressps_report), if the file name contains (partial_pressps_report$i) $i(1 or 2 or 3) then ($i) should be incremented and printed

use strict; use warnings; my $topdir = 'D:/PGN/ELSEVIER/FNS/1(1)/press'; opendir(HU, "$topdir"); my @files = grep(/\.txt$|.TXT$/,readdir(HU)); closedir(HU); my $ucount = 0; foreach(@files) { my $frame = $files[$ucount]; if($frame =~m#^partial_pressps_report#gs) { my $frameu = my $frame; } else { print "$frame"; } $ucount++; }

Thanks,

W. Ahmed

Replies are listed 'Best First'.
Re: name of the last file
by ansh batra (Friar) on Nov 09, 2011 at 06:47 UTC
    use strict; use warnings; my $topdir = '/home/ansh/perlmonks'; opendir(HU, "$topdir"); my @files = grep(/\.txt$|.TXT$/,readdir(HU)); closedir(HU); #print "@files"; #my $ucount = 0; foreach my $file(@files) { #my $frame = $files[$ucount]; if($file =~ /^p(1|2|3)/) { print "$file\n"; # my $frameu = my $frame; } else { #print "$frame"; } # $ucount++; }


    output
    p1.txt p3.txt p2.txt


    does this solve your problem???