Perl

From Mesopoly 3.0
Revision as of 14:43, 30 October 2009 by Zlatko (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

open and print file with name matching

bash-2.05# cat perl_procesor.pl

  1. !/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 );