in reply to Re^4: What is the easiest way to merge two hashes?
in thread What is the easiest way to merge two hashes?

In may solution it is enough to query the keys of both hashes without ever creating the merged hash itself.

Sorry, but that is rubbish. This code:

my $joined_keys = [ keys( %{ { map { $_=>undef } keys( %{$hash1} ) , keys( %{$hash2} ) +} } ) ]; # This.....^.......................................................... +..^ *is a hash* built from #...............................^^^^^^^^^^^^^^^^^...^^^^^^^^^^^^^^ #...the combined (potentially huge) lists of the keys from both hashes + PLUS #.....................^^^^^...undef as the value for each key in the c +ombined list...

And is functionally and memory consumption-wise, nearly identical to this code:

sub mergedHashKeys{ [ keys %{ { %{ $_[0] }, %{ $_[1] } + } } ] };;

And, your code creates *two (potentially) huge lists*; one going into the map and one coming out that is twice as long; from which the combined hash is constructed.

Any memory savings will be minimal.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked