Difference between revisions of "Perl"

From Mesopoly 3.0
Jump to navigation Jump to search
m
 
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
==check open files and send alarm if needed==
 +
 +
 
== 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 17: Line 20:
 
         open (FILE,$entry);
 
         open (FILE,$entry);
 
                 while ($line2print = <FILE>) {
 
                 while ($line2print = <FILE>) {
                print $line2print;
+
                        if ($line2print =~ m/test/){
 +
                        #system("perl /export/home/scripts/test/test_savegroup.sh") ;
 +
                        system("./test_print.pl");
 +
                        }
 
                 }
 
                 }
 
         close (FILE);
 
         close (FILE);
 +
       
 +
        $entry2 = $entry;
 +
        $entry2 =~ s/done/DON/;
 +
        #print "$entry2\n";
 +
        rename ($entry,$entry2);
 
         }
 
         }
 +
       
 
}
 
}
  
 
closedir( DIR );
 
closedir( DIR );
 +
 +
</pre>

Latest revision as of 10:56, 11 May 2011

check open files and send alarm if needed

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>) {
                        if ($line2print =~ m/test/){
                        #system("perl /export/home/scripts/test/test_savegroup.sh") ;
                        system("./test_print.pl");
                        }
                }
        close (FILE);
        
        $entry2 = $entry;
        $entry2 =~ s/done/DON/;
        #print "$entry2\n";
        rename ($entry,$entry2);
        }
        
}

closedir( DIR );