Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: how do I efficiently remove one hash from another?

by tobyink (Abbot)
on Nov 27, 2012 at 10:26 UTC ( #1005829=note: print w/ replies, xml ) Need Help??


in reply to Re: how do I efficiently remove one hash from another?
in thread how do I efficiently remove one hash from another?

The former compiles to a much smaller op tree than the latter:

perl -MO=Concise -e'delete @hash1{keys %hash2}' perl -MO=Concise -e'delete $hash1{$_} for keys %hash2'

On my machine, the slice performs about 20% faster than the loop.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re^2: how do I efficiently remove one hash from another?
Download Code
Re^3: how do I efficiently remove one hash from another?
by ColonelPanic (Friar) on Nov 28, 2012 at 14:25 UTC
    The slice option only calls delete once. It also doesn't have to go the trouble of assigning $_ for each element. So that makes sense.


    When's the last time you used duct tape on a duct? --Larry Wall

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-04 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls