Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

(zdog) Re: Confused by a Conditional

by zdog (Priest)
on Jun 09, 2001 at 21:58 UTC ( #87211=note: print w/replies, xml ) Need Help??

in reply to Confused by a Conditional

Here's another way of doing it in addition to the ones already mentioned:

if (' ID TITLE GENE CYTOBAND LOCUSLINK CHROMOSOME SCOUNT ' =~ m/ $key +/) { print "stuff.\n"; }

NOTE: The spaces in this solution are key in making sure the right word is being matched.

Zenon Zabinski | zdog |

Replies are listed 'Best First'.
Re: (zdog) Re: Confused by a Conditional
by ZZamboni (Curate) on Jun 09, 2001 at 22:06 UTC
    Note that if $key is a user-provided value, doing this is not a good idea. At the very least you would want to enclose the whole thing in an eval in case $key contains some characters that upset the match operator (for example, if $key contains **, the program will die with "nested *?+ in regexp"). In the worst case, $key could contain something that makes Perl execute arbitrary code. So for doing something like this, you have to make sure that $key is properly untainted.

    Update: You could also use \Q, as in "string" =~ m/ \Q$key /


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://87211]
[LanX]: belg4mit: thanks for fixing your CB log!

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2018-06-23 15:03 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.