Solved

Providing a hitcounter for Matt's Simple Search

Posted on 1998-08-19
3
248 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now