Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Perl Idioms Explained (explained)

by Aristotle (Chancellor)
on Aug 06, 2003 at 14:47 UTC ( #281421=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Perl Idioms Explained - keys %{{map{$_=>1}@list}}
in thread Perl Idioms Explained - keys %{{map{$_=>1}@list}}

Yep. As I said, it does not iterate on the Perl side. The pertinent nodes in optree are only ever seen once, and the loop is implicit in the execution of that single op. With all other approaches, the pertinent ops have to be dispatched and executed as many times as there are items in the list.

In fact, the keys %{{map{$_=>1}@list}} approach needs to first iterate over all elements of @list for the map, building a list as it goes, then build another list for keys.

In contrast, the @uniq = grep ! $seen{$_}++, @list; approach only builds a list once, while iterating over the elements of @list.

And of course as already explained, undef @seen{@list}; @uniq = keys %seen; just builds a single list - without iterating at all.

Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://281421]
help
Chatterbox?
[LanX]: damn my headphones were not plugged and the video blasted thru the office ...
[LanX]: xD
[LanX]: .. my boos woke up... ;-)
[Eily]: nice to see I'm not the only one looking like a fool at work
Eily answered a message but made the smiley on his face instead of in the message

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2017-09-20 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (237 votes). Check out past polls.

    Notices?