• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Providing a hitcounter for Matt's Simple Search

I'm currently using Matt Wright's Simple Search engine (located at http://worldwidemart.com/scripts/search.shtml ) to search my web pages. It is a basic search so it does not give many options. I would like to have a hitcounter that counts the number of hits that the search produces, so an appropriate response page can be produced. I don't think it's too difficult, but I can't do it. As I'm new to Perl,  can you please tell me how and exactly where to place this hit counter? Thanks!
0
zgee
Asked:
zgee
  • 2
1 Solution
 
evilgregCommented:
So you want to be able to show the number of matches produced?

If so, try this:

Right after
sub return_html {

add in:

$matches=0;
foreach $x (keys %include) {
  if ($include{$x} eq 'yes') { $matches++; }
}

Then just use $matches in your output message, such as:
if (!$matches) {
  print "Sorry, no matches found!\n";
}
else {
  printf("I found $matches %s!\n", $matches==1 ? "match" : "matches");
  ## Detail of matches here....
}


0
 
evilgregCommented:
So you want to be able to show the number of matches produced?

If so, try this:

Right after
sub return_html {

add in:

$matches=0;
foreach $x (keys %include) {
  if ($include{$x} eq 'yes') { $matches++; }
}

Then just use $matches in your output message, such as:
if (!$matches) {
  print "Sorry, no matches found!\n";
}
else {
  printf("I found $matches %s!\n", $matches==1 ? "match" : "matches");
  ## Detail of matches here....
}


0
 
ozoCommented:
#A simpler way to say
   $matches=0;
   foreach $x (keys %include) {
     if ($include{$x} eq 'yes') { $matches++; }
   }
#is
  $matches=grep{$_ eq 'yes'}values %include;
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now