Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: How to check if a variable's value is equal to a member of a list of values

by LanX (Chancellor)
on Mar 25, 2013 at 14:09 UTC ( #1025310=note: print w/replies, xml ) Need Help??

in reply to How to check if a variable's value is equal to a member of a list of values

could you please elaborate more, I don't really understand your usage of values and keys.

lookups of strings (!) are most efficient with hashes, ...

> then just using something like 1 for the value.

... and you don't need to assign any value, undef is enough

my %look; @look{@set_of_values}=(); ... print "gotcha" if exists $look{$to_check};

You're free to put anything other than undef in the slots if you need to do further checks.

Someone proposed using smartmatch ~~, but I doubt this scales well in repeated use (if their is no magic background optimization happening)

Cheers Rolf

( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025310]
choroba finds working in a small company boring comparing to a large corporation
[MidLifeXis]: At least test before mass distribution.
[MidLifeXis]: More opportunities for anonymous snafus :-)
[MidLifeXis]: In a small group / company, at least you know who needs to buy the next round of beer for their mess-up.
[MidLifeXis]: :-)
[Discipulus]: are sure you are not really named "%Firstname% %Lastname%..." ? have you check your identity card?
[Discipulus]: Bobby Tables?

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-01-19 12:19 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (170 votes). Check out past polls.