in reply to Finding names in files

first, a couple command-line solutions:
#bash: for f in `find /tmp/files/`; do head -20 $f | grep -q -i dave && echo +$f >> list.txt ; done perl -lne 'do { print $ARGV; last } if /DAVE/i; last if $. == 20' `fi +nd /tmp/files` >> list.txt
Now, addressing your code, couple starting points: note that $. (see perlvar) can be used instead of $count ; instead of string matching 'Dave' (which is why the case has to be exact), use a regular expression of /dave/i (or maybe /\bdave\b/i) -- see perlre for tons of regexp info.
Also, why use File::Find if you're given a single filename to start with?

Replies are listed 'Best First'.
Re^2: Finding names in files
by gzayzay (Sexton) on Mar 29, 2006 at 17:36 UTC
    I am searching multiples files that end with .c, .h, and .pr (56 in total). That is why I am using File::Find.
      consider File::Find::Rule to simplify things:
      my @files = File::Find::Rule->file()->name->( '*.c', '*.h', '*.pr' )-> +in(qw( /tmp/dir1 /tmp/dir2 ));