Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Fixing: Experimental keys on scalar is now forbidden

by ikegami (Patriarch)
on Jun 06, 2018 at 07:27 UTC ( [id://1216000]=note: print w/replies, xml ) Need Help??


in reply to Fixing: Experimental keys on scalar is now forbidden

Better solution:

my %seen; my @uniqWebCustomers = grep !$seen{$_}++, @webCustomers;

Better yet:

use List::Util qw( uniq ); my @uniqWebCustomers = uniq @webCustomers;

Replies are listed 'Best First'.
Re^2: Fixing: Experimental keys on scalar is now forbidden
by kennethk (Abbot) on Jun 06, 2018 at 14:42 UTC
    I agree with the "Better yet," but in situations where I do something like option 1, I like to wrap it in a do block to maintain tight scoping:
    my @uniqWebCustomers = do{ my %seen; grep !$seen{$_}++, @webCustomers; };

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      If you're going to add a block, make it a sub.

      sub uniq { my %seen; grep !$seen{$_}++, @_ } my @uniqWebCustomers = uniq @webCustomers;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found