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

I have a search that gives me total number of hits. Now I need to just give me unique page hits instead of total number of hits. So if one of my two variables I am searching come up a couple times on a web page it should just count as one web page hit. Iam trying to find a total of how many web pages have at least one of these variables $nameOne and $nameTwo.
use strict; use File::Find; my $dir = 'C:\directoryHere'; my $ct = 0; my $hit; my $line; my $nameOne = 'Jackson and Smith and Richards'; my $nameTwo = 'JSR'; my @data; my @files; sub mySub { if( $_ =~ /\.(?:html?|cfm|cfml|cgi|js|pl|asp)$/) { my $name = $File::Find::name; open ( FLE, $name ) || warn "Can\'t open File $name: $!\n"; while($line = <FLE>) { for $hit ($line =~ /(?:$nameOne|$nameTwo)/gi) { print "WEB PAGE ->\t$name\n"; $ct++; } } close FLE; } } find( \&mySub, $dir ); print "Total Web page matches = $ct\n";

Replies are listed 'Best First'.
Re: Counting web page hits
by Roy Johnson (Monsignor) on Mar 02, 2004 at 20:15 UTC
    Is this what you want?
    while($line = <FLE>) { if ($line =~ /(?:$nameOne|$nameTwo)/i) { print "WEB PAGE ->\t$name\n"; $ct++; last; } } close FLE;

    The PerlMonk tr/// Advocate
      Thanks that works.