Dear List,

I am new to programming and currently looking into
Perl. I am going thru the available Perl tutorial in
the net but there are less examples especially on how
to use modules.

I have wrote this simple script of match word and
count it for a text file (well, did some cut-n-paste
here and there). I wanted to extend it by putting an
interface- webpage with a searchbox to post the search
word to this script.

I have tried CGI.pm but I failed to read/pass the
search word to script. Please take a look at this
script and html file . Please mind me if there's
really stupid mistakes since I desperately need some
help.

Really looking forward to hear from the list asap.Your
help is very much appreciated.

Rgds,

P/S: I have attached the following:
      match.txt - original sript without cgi
      matchcgi.txt - using CGI.pm 
      match.htm 

#!usr/perl/bin

@ARGV = "C:\\Perl\\bin\\folder\\princess.txt";
use CGI;
$q = new CGI;
$pattern =  $cgi-> param("query");

chop($pattern);
$filename = $ARGV [0];
$count =0;

print $q-> header(),
print $q-> start_html,
print $q-> <h1> TheOutputs,/h1>\n",
print "Matches found : $pattern\n";

while ($line = <>) {
          if  ($line =~ (/$pattern/)) {
               @words = split (/$pattern/, $line);
                $count += @words-1;
                            
}
 
if (eof) {
        $filename = $ARGV[0]; }
      
}

if ($count == 0 ) {
    print "No matches found. \n";
} else {
     print "Total numbers of matches : $count \n";
}

print $q-> end_html
#!usr/perl/bin

@ARGV = "C:\\Perl\\bin\\folder\\princess.txt";

print "Enter your search pattern: ";
$pattern =<STDIN>;
chop($pattern);
$filename = $ARGV [0];
$count =0;
print "Matches found :\n";

while ($line = <>) {
          if  ($line =~ (/$pattern/)) {
               @words = split (/$pattern/, $line);
                $count += @words-1;
                            
}
 
#Pointing back to the first element in text after EOF
if (eof) {
        $filename = $ARGV[0]; }
      
}

if ($count == 0 ) {
    print ("No matches found. \n");
} else {
     print "Total numbers of matches : $count \n";
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to