http://www.perlmonks.org?node_id=497647


in reply to Re: pattern match a name from stdin
in thread pattern match a name from stdin

this now works:
if (m/\|\Q$file/) {print $num_entry};
However, if i want the match to occur at at the end i would include an addition $
if (m/\|\Q$file$/) {print $num_entry};
For example if the user entered Sarah it could output Sarah and Sarah-jane. But this second bit of code doesnt seem to work?

Replies are listed 'Best First'.
Re^3: pattern match a name from stdin
by japhy (Canon) on Oct 05, 2005 at 16:34 UTC
    The \Q is making the '$' match a literal '$'. You want  m/\Q|$file\E$/, methinks.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart