Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: in_array and skipping foreach

by jdporter (Canon)
on Jan 16, 2020 at 16:34 UTC ( #11111494=note: print w/replies, xml ) Need Help??


in reply to in_array and skipping foreach

Any ideas how I can make this better?

Any will do it! Specifically, the any function from the List::Util module:

use List::Util qw( any ); next if any { $_ eq $offer{retailer} } @ignore_merchants;

Many cases of using grep in a conditional can be written using any instead, as it can short-circuit after the first true result.

Of course, a hash is better if you're going to be doing this check a lot of times.

I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2020-06-07 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (42 votes). Check out past polls.

    Notices?