Using grep with the file-test operators. : grep « Regular Expression « Perl






Using grep with the file-test operators.

     
#!/usr/local/bin/perl 

opendir(CURRDIR, ".") || 
die("Can't open current directory"); 
@filelist = grep (!/^\./, grep(-r, readdir(CURRDIR))); 
closedir(CURRDIR); 
foreach $file (@filelist) { 
    open (CURRFILE, $file) || die ("Can't open input file $file"); 
    while ($line = <CURRFILE>) { 
        if ($line =~ /$ARGV[0]/) { 
            print ("$file:$line"); 
        } 
    } 
    close (CURRFILE); 
} 

   
    
    
    
    
  








Related examples in the same category

1.grep value
2.grep with regular rxpression
3.grep {$_ *= 2}
4.Using grep function
5.Using grep to remove word
6.Using grep with expression
7.The grep function evaluates the expression (EXPR) for each element of the array (LIST).
8.grep function with regular expression