![]() So when you use foreach() you are slurping the entire file in memory before looping through the files. In a foreach statement, the expression in parenthesis is evaluated to produce a list. One thing: you should use while instead of foreach. There's a few optimizations with qr// if you're really into speed, I think you introduced unneeded complexity here. Thanks for the tips! I've modified the above snippet, including your suggestions, as well as added a few regex's to strip out initial whitespace, as well as added the ability to specify a file extension (actually, a file pattern match).įor example, I just used "grep checkbox php" to grep all php files for a checkbox. ![]() RE: RE: Recursively grep through directory trees. variableĮuropean Perl Conference - Sept 22/24 2000, ICA, London You use the variable $count to keep track of the current line number, but Perl already does that for you in the $.Instead of if (-d) why not just use return if -d.RE: Recursively grep through directory trees. Jumps down directories to searchĭie "Usage : ggrep searchstring extension\n" if ($searchstring eq "") # By Greg Flanders Opens each file from currenct directory and searches Also allows users to specify a filename pattern, example searching pl or php or html files. This should also be possible with a combination of xargs and grep, but I liked this solution better, with line numbers and path location included. Where I work we have directories full of code, and I found it a hassle to wade through each directory to grep through the files. ![]() I am always looking at other people's code to find examples of what I want to do.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |