craziest
asked on
Perl Double quote problem.
Hello guys,im new to perl so i got a small problem here.Glad if anyone could help.
Im building a personal search engine and i would like to use double quotes to get the exact word/words.I got stuck and didnt know where to specify the double quotes to do the action.
My code:
#!c:/perl/bin/perl
read(STDIN, $buffer,$ENV{'CONTENT_LENG TH'});
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$p air);
$value =~ tr/+/ / ;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9] )/pack("C" , hex($1))/eg;
#$value=~ s/\"//g; # strip double quotes
$formdata{$key}.="$value";
}
$search=$formdata{'search' };
open(INFO, "Docs.htm")or die "Can't open file for output"; # Open db for reading
@array=<INFO>;
close (INFO);
$count = 0;
print "Content-type:text/html\n\ n"; #Content Header
print <<End_of_head;
<html>
<head><title>.::Search Results::.</title></head>
<body>
<h5>You Searched for :$search</h5>
End_of_head
if($search eq "")
{
print "Error: Please type something";
}
else{
#Both of the words
$search =~ s/^\s+//;
@cut = split(/\W/, $search);
foreach $line (@array){
$count++;
if (($line =~ /\b$cut[0]\b/i ) && ($line =~ /\b$cut[1]\b/i )) {
print <<End_of_line;
<font color="Red">Line<b> $count:</font> $line <br>
End_of_line
}
}
}
#Exact word
if ($search eq "'")
{
foreach $line (@array){
$count++;
if ($line =~ /\b$search\b/i ){
print <<End_of_line;
<font color="Red">Line<b> $count:</font> $line <br>
End_of_line
}
}
}
print <<End_of_Doc;
</body>
</html>
End_of_Doc
Im building a personal search engine and i would like to use double quotes to get the exact word/words.I got stuck and didnt know where to specify the double quotes to do the action.
My code:
#!c:/perl/bin/perl
read(STDIN, $buffer,$ENV{'CONTENT_LENG
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$p
$value =~ tr/+/ / ;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9]
#$value=~ s/\"//g; # strip double quotes
$formdata{$key}.="$value";
}
$search=$formdata{'search'
open(INFO, "Docs.htm")or die "Can't open file for output"; # Open db for reading
@array=<INFO>;
close (INFO);
$count = 0;
print "Content-type:text/html\n\
print <<End_of_head;
<html>
<head><title>.::Search Results::.</title></head>
<body>
<h5>You Searched for :$search</h5>
End_of_head
if($search eq "")
{
print "Error: Please type something";
}
else{
#Both of the words
$search =~ s/^\s+//;
@cut = split(/\W/, $search);
foreach $line (@array){
$count++;
if (($line =~ /\b$cut[0]\b/i ) && ($line =~ /\b$cut[1]\b/i )) {
print <<End_of_line;
<font color="Red">Line<b> $count:</font> $line <br>
End_of_line
}
}
}
#Exact word
if ($search eq "'")
{
foreach $line (@array){
$count++;
if ($line =~ /\b$search\b/i ){
print <<End_of_line;
<font color="Red">Line<b> $count:</font> $line <br>
End_of_line
}
}
}
print <<End_of_Doc;
</body>
</html>
End_of_Doc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
s/</</g, s/>/>/g for $line;
ASKER
if u dont mind,whats the regex for showing the tags in the file eg.
<TITLE> Hello</TITLE>
This doesnt show up when im searching.
Thanks again for your help.