Difference between revisions of "Perl"
Jump to navigation
Jump to search
m |
m |
||
| Line 1: | Line 1: | ||
== open and print file with name matching == | == open and print file with name matching == | ||
| − | + | <pre> | |
bash-2.05# cat perl_procesor.pl | bash-2.05# cat perl_procesor.pl | ||
#!/usr/bin/perl | #!/usr/bin/perl | ||
| Line 24: | Line 24: | ||
closedir( DIR ); | closedir( DIR ); | ||
| + | </pre> | ||
Revision as of 15:16, 30 October 2009
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 );