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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.