Gheek.net

January 27, 2008

ciscopricelist_cgi

Filed under: cgi, perl — Tags: , , — lancevermilion @ 11:12 pm
#!/usr/local/bin/perl -w
#Author:  Lance Vermilion
#Purpose: Search the Cisco price list that is tab delimited and then
#         return the values that are found.
##########################################################################

use CGI qw(:standard);

####
# Variables
####

  my $searchval = param('searchval');
  my $file = '/usr/local/www/data/ciscopricelist/global.txt';
  my $count = 0;
  my @data;

####
# Open the that is specified as the variable $file
####
open my $fh, '<', $file
  or die $!;

####
# This is our usage page. It is used when someone doesn't enter data
####
sub usage () {
print
  "Content-type: text/html\n\n" .
  "\n\n" .
  "Cisco Price List Search Results\n" .
  "\n" .
  "\n" .
  "

ERROR

\n" . "

\n" . "\n"; print "\nYOU MUST FILL OUT EVERY FIELD\n"; print "\n" . "\n\n"; exit 0; } #### # Check to see if the user entered something, if not error and exit #### if ( $searchval eq "" ) { &usage; exit 0; } #### # While the file is open search for stuff and push entires into an array #### while() { chomp; if ( /$searchval/i ) { $count++ ; if ( /^[a-zA-Z]/i ) { my @columns = split/ /; #print " # $columns[0] # "; push @data, "$columns[0]"; } elsif ( /^\t[a-zA-Z0-9]/i ) { @columns = split/ /; #print " #  &nbsp$columns[1] # "; push @data, " &nbsp$columns[1]"; } else { @columns = split/ /; #print "   &nbsp$columns[2]$columns[3]$columns[4]$columns[ 5]"; push @data, "   &nbsp$columns[2]$columns[3]$columns[4]$col umns[5]"; } } } close($fh); #### # Print webpage #### print "Content-type: text/html\n\n" . "\n\n" . "Cisco Price List\n" . "\n" . "\n" . "

Results while searching for: $searchval

\n" . "

\n" . "\n"; print "Found $count matches for $searchval in the Cisco Price List\n"; print "

";
  print "";
  if (! @data )
  {
    print "NO MATCH found for $searchval";
  }
  else
  {
    print @data;
  }
  print "
"; print "
"; print 'Comments or Questions email Lance Vermilion'; print "

\n";

####
# Exit the cgi script once it is done
####
exit 0;

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: