Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: hey how to recursively access the directroies to search for a keyword and print its file name and the keyword line?

by haukex (Archbishop)
on Feb 18, 2018 at 11:41 UTC ( [id://1209422]=note: print w/replies, xml ) Need Help??


in reply to hey how to recursively access the directroies to search for a keyword and print its file name and the keyword line?

Welcome to the Monastery, harishnv. I can't tell if your post was always empty or if you've removed its contents, but either way, please see How do I post a question effectively? for some guidelines on how to best ask questions. Normally, it'd be good if you include the code you have tried, how you expect it to behave, what is going wrong with it including exact error messages, and any other information so that we can reproduce the situation on our end, for example sample input and the expected output for that input. A question consisting of just the title is normally not enough information to go on. Please see How do I change/delete my post? for how to edit your node to include more information.

hey how to recursively access the directroies to search for a keyword and print its file name and the keyword line?

For recursively finding files, you could use the core module File::Find, or with a nicer interface File::Find::Rule. Then, for each file, you could open it, read it line-by-line, use a regular expression to find matches, and get the current line number from the special variable $.. Everything you need for that is explained in perlintro, pay particular attention to the description of foreach (for looping over a list of files) and the sections "Files and I/O" and "Regular expressions".

  • Comment on Re: hey how to recursively access the directroies to search for a keyword and print its file name and the keyword line?
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found