Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Perl Double quote problem.

Posted on 2006-11-04
Medium Priority
Last Modified: 2013-12-25
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:
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
$value =~ tr/+/ / ;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
#$value=~ s/\"//g; # strip double quotes
open(INFO, "Docs.htm")or die "Can't open file for output"; # Open db for reading
close (INFO);
$count = 0;
print "Content-type:text/html\n\n"; #Content Header
print <<End_of_head;
<head><title>.::Search Results::.</title></head>
<h5>You Searched for :$search</h5>
   if($search eq "")
print "Error: Please type something";
       #Both of the words
     $search =~ s/^\s+//;
     @cut = split(/\W/, $search);
     foreach $line  (@array){
     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>
      #Exact word
    if ($search eq "'")
       foreach $line  (@array){
     if ($line =~  /\b$search\b/i ){       
print <<End_of_line;
<font color="Red">Line<b> $count:</font> $line <br>
print <<End_of_Doc;
Question by:craziest
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 84

Accepted Solution

ozo earned 1600 total points
ID: 17873388
@cut = grep{defined}$search =~ /(\w+)|"([^"]+)"/g;
if( !@cut ){
   print "Error: Please type something";
     foreach $line  (@array){
         if ( !grep{$line !~  /\b\Q$_\E\b/i} @cut ){
print <<End_of_line;
<font color="Red">Line<b> $count:</font> $line <br>

Author Comment

ID: 17873423
Thats short and simple,worked well thanks!
if u dont mind,whats the regex for showing the tags in the file eg.
This doesnt show up when im searching.
Thanks again for your help.
LVL 84

Expert Comment

ID: 17873438
s/</&lt;/g, s/>/&gt;/g for $line;

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

670 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