in reply to How to Check the file names while reading from the array.
How can i place more check before i read a file
What means "more check"?
I am expecting the output as below:
Here you go
print q{File - 1 := Check_1.ABC19.dat.gz File - 2 := CSEK.1.ABC19_KLJK_TT1.dat CSEK.1.ABC19_AB_TT1.dat File - 3 := CSEK.1.ABC19.dat };
Here you go
#!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Main { my( @files ) = @_; if( not @files ){ @files = \q{CSEK.1.ABC19_KLJK_TT1.dat CSEK.1.ABC19_AB_TT1.dat Check_1.ABC19.dat.gz CSEK.1.ABC19.dat }; } for my $file( @files ){ doFileStuff( $file ); } } sub doFileStuff { my( $file ) = @_; open my( $filehandle ), '<', $file; my $nfile = 0; while( my $file = readline $filehandle ){ $file =~ s/\s+$//; ## trim trailing whitespace if ($file =~ m/^Check/) { $nfile++; print "File - $nfile :=$file\n"; } elsif ($file =~ m/^CSEK.*TT1.dat$/) { $nfile++; print "File - $nfile :=$file\n"; } elsif ($file =~ m/^CSEK.dat$/) { $nfile++; print "File - $nfile :=$file\n"; } else { printf "%10s %s\n", ' ', $file; } } close $filehandle; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to Check the file names while reading from the array.
by Anonymous Monk on Jun 07, 2013 at 10:43 UTC |