Perl
Jump to navigation
Jump to search
open and print file with name matching
bash-2.05# cat perl_procesor.pl
- !/usr/bin/perl
$path = shift; $path = "." unless $path;
opendir( DIR, $path ) or die "Can't open $path: $!";
while ( $entry = readdir( DIR ) ) {
$type = ( -d "$path/$entry" ) ? "dir" : "file"; # $path is crucial!
if ($type eq dir){
next;
}
if ($entry =~ m/done/){
open (FILE,$entry);
while ($line2print = <FILE>) {
print $line2print;
}
close (FILE);
}
}
closedir( DIR );