Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: in_array and skipping foreach

by jdporter (Paladin)
on Jan 16, 2020 at 16:34 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11111494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found