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

Re^3: pattern search in all the files in a directory

by 2teez (Priest)
on Feb 19, 2013 at 07:46 UTC ( #1019474=note: print w/ replies, xml ) Need Help??


in reply to Re^2: pattern search in all the files in a directory
in thread pattern search in all the files in a directory

Actually I am not able to take an exact move at this point Why is that?
I thought of using find(subroutine,directory_path) That is a way to go. Try it out.
If you could describe what you want like you did above, it shows you could make it happen. Try it out and you would be glad you did.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re^3: pattern search in all the files in a directory
Download Code
Re^4: pattern search in all the files in a directory
by Bharath666 (Novice) on Feb 19, 2013 at 09:58 UTC

    I tried like the below and I got the solution that I desired. Can you please tell me if it can be further optimized or is enough to get proceed further? Thanks

    find(\&do_process, "$dirname" ); sub do_process { chomp($_); if (-r "$_"){ $file_name = $_; open (my $fh,"< $file_name"); while(<$fh>) { chomp(); if (/\bkeyword : Multinode\b/i) { $KeyMnode = "$file_name:$_"; } if (/\bkeyword : Threads\b/i) { $KeyThreads = "$file_name:$_"; } } } }

      • The perl function chomp chomps $_ if variables are omitted i.e chomp($_) can be written simply as chomp;
      • Use 3 argument open function and also check the return of the open function like so
        open my $fh, "<", $file_name or die "can't open file: $!"; while(<$fh>){ chomp; ... } ...

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-09-16 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (48 votes), past polls