Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Comparing against multiple values (boo)

by boo_radley (Parson)
on Mar 18, 2002 at 19:36 UTC ( #152573=note: print w/replies, xml ) Need Help??

in reply to Comparing against multiple values

While that's very easy, it's not as fast as using a comparison operator such as 'eq' or '=='. However using these often leads to redundant and cumbersome looking code:
have you met my friend, grep?

my @values= qw(foo bar baz bax); my $test = "foo"; print "woo\n" if (grep {$_ eq $test}@values) ;
This is probably not the hottest use for grep if you've got a long list of values, since it'll build an array of values matching the test only to use the result in a scalar fashion. It'd be handy if you could last in a grep in this particular instance.
You could produce the same behavior in a for loop quite easily that would exit on the first found value.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152573]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2018-07-23 13:47 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (468 votes). Check out past polls.