Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Multiple file handling

by tobyink (Abbot)
on Sep 12, 2012 at 14:56 UTC ( #993237=note: print w/ replies, xml ) Need Help??


in reply to Multiple file handling

I'm not entirely sure I understand your requirements, but...

use 5.010; use Path::Class qw(dir file); say "GOT $_" for grep_dir_recursively( qr(say), # pattern to grep for (with smartmatch) qr(\.pl$), # pattern to match file names (with smartmatch) '/home/tai/tmp', # directory to search ); sub grep_dir_recursively { my $text_pattern = shift; my $file_pattern = shift; my @results; for my $root (@_) { dir($root)->recurse(callback => sub { my $file = shift; return if $file->is_dir; return unless $file ~~ $file_pattern; my $fh = $file->open; while (<$fh>) { if ($_ ~~ $text_pattern) { push @results, $file; last; } } }); } return @results; }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Multiple file handling
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993237]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-08-30 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls