Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: pattern match a name from stdin

by JediWizard (Deacon)
on Oct 05, 2005 at 15:44 UTC ( [id://497644]=note: print w/replies, xml ) Need Help??


in reply to pattern match a name from stdin

First: You should probably chomp $file.

Secod: if $file contains any metacharacters, they will need to be escaped (see quotemeta).

Third: If you are testing for the presence of a literal sting within another sting you may be better off with index (in which case disregard the use of quotemeta)


They say that time changes things, but you actually have to change them yourself.

—Andy Warhol

Replies are listed 'Best First'.
Re^2: pattern match a name from stdin
by Anonymous Monk on Oct 05, 2005 at 15:56 UTC
    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?
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found