Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by diotalevi (Canon)
on Aug 04, 2003 at 15:41 UTC ( #280711=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}}

Yes. Instead of one scalar of the value '1' for every key, you get to share the same undef value for all the keys and thus don't have to allocate tons of memory you aren't going to use anyway. So keys @{{map { $_, undef } @ary}} has the potential to be a lot cheaper than keys @{{map { $_, 1 } @ary}}. The "a lot" part is just related to how many values are in your array. You burn one extra value for every entry in @ary and I'm just suggesting that you don't have to do that in this case.

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://280711]
help
Chatterbox?
[Corion]: choroba: Yeah - I found that if you have the "right" datastructure from the start, it's fairly easy, but if you have some global datastructure that you mutate, you have to rewrite a lot to pass around the results instead.
[Corion]: I find the process quite similar to (in Prolog) passing around an accumulator variable in recursive predicates
[1nickt]: Good morning, brainy monks!
[marto]: Hi 1nickt, I know it's early days, but how is the new job?
[Corion]: Hi 1nickt!
[Corion]: Ohai marto!
[marto]: hey Corion

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-12-11 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (289 votes). Check out past polls.

    Notices?