On Jul 15, Vishal Kapoor said: >I want to read a few files and search for a particular word. I want to then >print a list of all the files with that word.
my @hits; my $word = "japhy"; { local @ARGV = @files_to_search; while (<>) { if (index($_, $word) != -1) { push @hits, $ARGV; close ARGV; } } } Instead of using index(), you can use a regex: if (/\b$word\b/) { ... } or perhaps if (/\b\Q$word\E\b/) { ... } if there's a chance there are regex metacharacters in $word. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]