Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to search directory

by mantra2006 (Hermit)
on Aug 22, 2006 at 12:28 UTC ( [id://568821]=note: print w/replies, xml ) Need Help??


in reply to How to search directory

hope this will help you

use strict; use warnings; use Cwd; use File::Find; my $search_pattern=$ARGV[0]; my $file_pattern =$ARGV[1]; find(\&d, cwd); sub d { my $file = $File::Find::name; $file =~ s,/,\\,g; return unless -f $file; return unless $file =~ /$file_pattern/; open F, $file or print "couldn't open $file\n" && return; while (<F>) { if (my ($found) = m/($search_pattern)/o) { print "found $found in $file\n"; last; } } close F; }

usage: perl find.pl (?i)sorting html
The first argument is the regular expression. I use (?i) to
indicate that I want to search case insensitive. The
second argument specifies that only files should be considered
that contain html in their name. Site where the code is available : http://www.adp-gmbh.ch/perl/find.html
Sridhar

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found