Solved

Providing a hitcounter for Matt's Simple Search

Posted on 1998-08-19
3
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse xml file 2 142
Search in text file in column and compare 4 75
Any syntax error for this clone.plscript 6 148
Create an automated page index 9 107
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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.…
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…

738 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