Solved

Providing a hitcounter for Matt's Simple Search

Posted on 1998-08-19
3
260 Views
Last Modified: 2010-08-05
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
Comment
Question by:zgee
  • 2
3 Comments
 
LVL 1

Expert Comment

by:evilgreg
ID: 1204407
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
 
LVL 1

Accepted Solution

by:
evilgreg earned 150 total points
ID: 1204408
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
 
LVL 84

Expert Comment

by:ozo
ID: 1204409
#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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question