Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Array of filehandles

by hdb (Prior)
on Apr 29, 2013 at 07:04 UTC ( #1031166=note: print w/replies, xml ) Need Help??


in reply to Array of filehandles

If you want the filenames and not the handles for the files that match the pattern, it is better to operate on the filenames and not the handles. If you want the handles, my code can be modified easily: just pass in the handles and remove the open statement.

use strict; use warnings; use autodie; sub findpattern { my $file = shift; my $pattern = shift; open my $fh, '<', $file; while(my $line=<$fh>){ return 1 if $line =~ /$pattern/; } return 0; } my @files = <*.pl>; my @success = grep { findpattern( $_, "Data::Dumper" ) } @files; print join "\n", @success, "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031166]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2016-12-09 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (157 votes). Check out past polls.