Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Help, directories?

by Rudolf (Pilgrim)
on Dec 05, 2012 at 15:36 UTC ( [id://1007308]=note: print w/replies, xml ) Need Help??


in reply to Help, directories?

Hello! I am a bit confused about what your trying to do EXACTLY but I made some assumptions. So I am assuming your just searching a bunch of files for a specific line or string and want to know which one/ones contain it. I wrote some code bellow, however since I dont know what kind of files your searching through the regex should be converted to your needs and if you're searching for strings that could be longer than one line, reading line by line won't catch it. Hope this helps atleast a little, unless I misunderstood your intentions, good luck!

use v5.14; my $dir = "C:\\Users\\Desktop\\collection2"; opendir(DR, $dir) || die "could not open directory: $!\n"; my @docs = grep{/[^\.|..]/} readdir DR; closedir DR; while ( chomp(my $query = <>) ) { foreach my $doc (@docs){ open(DOC,'<',"$dir\\$doc") or die "$!\n"; while(<DOC>){ chomp; if($query =~ m/$_/i){ print "$query appears in $doc\n"; } } close DOC; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found