in reply to Re: How to combine two different hashes into single hash.
in thread How to combine two different hashes into single hash.

Running your code I get "Can't use an undefined value as a HASH reference" (update: using warnings )

... and Perl exits "compilation exited abnormally with code 255 at Sun Dec 29 00:36:58" (update: using strict )

That's why I had to add the // {} parts in my code to default to an empty hash.

Did you tweak your Perl?

my version: This is perl 5, version 24, subversion 1 (v5.24.1) built for MSWin32-x64-multi-thread

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^3: How to combine two different hashes into single hash.
by tobyink (Canon) on Dec 29, 2019 at 00:56 UTC

    It'll do that with use strict.

    You could do this:

    my %output; $output{$_} ||= {( %{$VAR1->{$_}||{}}, %{$VAR2->{$_}||{}} )} for keys(%$VAR1), keys(%$VAR2);

    Not really any need to use the // operator which limits backwards compatibility. (Introduced in Perl 5.10.)