25 users online (2 members and 23 guests)  


  Results 1 to 2 of 2

Related

  1. Not random quote rotator    Forum: PHP Forum
    Replies: 0
  2. Iframe double scroll bar paradox    Forum: HTML Forum
    Replies: 1
  3. Perl quote    Forum: CGI Perl Forum
    Replies: 0
  4. Help: Double Or Triple Space Lines    Forum: HTML Forum
    Replies: 2
  1. #1
    craziest's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2006
    Posts
    1

    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. This is my code.
    Code:
    #!c:/perl/bin/perl
    read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/,$buffer);
    foreach $pair(@pairs){
    ($key,$value)=split(/=/,$pair);
    $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

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: Double quote problem.

    you could use a regexp to do what you want... i see in the code you use regular expressions a little...

    something like:

    /("([a-zA-Z0-9_-]*)*")*/g

    do that to check for exact phrases and use what you already have to do the rest...

    so, use what you have to catch the rest of them (excliding exact phrases) and use this one to catch the exact phrases...

    you could also delete the whole phrases in the search term then use what your script does to do the rest...

    in other words...

    if the search term is:

    "John Doe" sunny ground

    use that regexp to catch the "john doe" and use your script to catch "sunny" and "ground" sperate.

    but i havent used perl in such a long time it is getting harder and harder to help people with PERL

    -ALL



Tags for this Thread