in reply to Re: Re: File searching
in thread File searching

Thanks for all the help. It works and captures everything EXCEPT if I have multiple hits on one line it only captures the first one and then thats it for that line. I need it to capture all hits on the line. For example the below should give me 5 hits after I run the script:

%ff other%ff
other words%ff
%jj %bb otherstuff here


But my current script only gives me 3 hits because it counts one hit per line. I need it to count every match on every line. Please advise how I can get this to work now?
sub rout { local *FILE; if( $_ =~ /\.html?$/) { open ( FILE, $name ); while($hit = <FILE>) { if( $hit =~ /%(?:ff|jj|bb)/ ) { print "Hit = $1\n"; } } close FILE; } } find( \&rout, "/disk1/disk2" );

Replies are listed 'Best First'.
Re: Re: Re: Re: File searching
by diotalevi (Canon) on Jun 20, 2003 at 19:20 UTC
    sub rout { # Filename portion is in global $_ # Complete path is in global $name return unless /\.html?$/; local *FILE; open FILE, $name or die "Couldn't open $name for reading: $!"; while( my $line = <FILE> ) { for my $hit ( $line =~ /%(ff|jj|bb)/g ) { print "Hit = $hit\n"; } } close FILE or die "Couldn't close $name after reading: $!"; } find( \&rout, "/disk1/disk2" );
      Thank you. You just solved a problem that I have been working on for hours.Thanks!!!