Here's another problem:
... $findit .= "/\Q$term\E/i $param ";
It appears that you want the match to be case insensitive when matching $term. The way to specify that is as follows:
$findit_re = "\\b(?i:\Q$term\E)\\b";
This turns on case-insensitive matching for $term. Also, note the use of double-slashes since double quotes are being used. An easier way to write this is to use qr//:
$findit_re = qr/\b(?i:\Q$term\E)\b/;

At first I thought you were confused about the use of \Q...\E. After more carefully reading your response I don't think this is the case, but here is what I wrote about it:

\Q and \E is simply another way of invoking the the quotemeta() function - it just escapes characters which are used to denote regular expression elements.

For instance, suppose you wanted to search for the three character sequence [a], i.e. a left bracket, the letter 'a', and then a right bracket, If you used the regular expression:

my $target = "[a]"; if ($string =~ m/$target/) { ... }
it wouldn't work as you wanted because the brackets would be be interpreted as being part of the character class regex element. You can fix things by using quotemeta or \Q...\E as follows:
my $target = "[a]"; if ($string =~ m/\Q$target\E/) { ... } # or: my $re = quotemeta($target); if ($string =~ m/$re/) { ... }
Now you'll only get a match if $string contains the three character sequence [a].

Another way to think about it is that the quotemeta is a function which converts a string to a regular expression which matches exactly that literal string.


In reply to Re^3: Exact Word Search While Using \Q & \E by pc88mxer
in thread Exact Word Search While Using \Q & \E by Gwalchmai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.