Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How to search directory

by arunmep (Beadle)
on Aug 22, 2006 at 12:12 UTC ( [id://568817]=perlquestion: print w/replies, xml ) Need Help??

arunmep has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How to search directory
by imp (Priest) on Aug 22, 2006 at 12:36 UTC
    File::Find::Rule provides an easier interface for this. Here's an example:
    use File::Find::Rule; use strict; use warnings; my $rule = File::Find::Rule->file->grep(qr/perl/)->start('.'); while (my $file = $rule->match) { print $file, "\n"; }
Re: How to search directory
by Joost (Canon) on Aug 22, 2006 at 12:23 UTC
Re: How to search directory
by mantra2006 (Hermit) on Aug 22, 2006 at 12:28 UTC
    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
Re: How to search directory
by planetscape (Chancellor) on Aug 23, 2006 at 13:28 UTC

    Depending on your needs, you might also wish to look at egrep and tcgrep.

    HTH,



    planetscape
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found