You don't normally need to initialize (autovivification will take care of this) but you can use the ||= construction:
for (@somelist) { my($foo,$bar) = split; my $x = somecalc($foo,$bar); $somehash{ $foo }->{ $bar } ||= []; push @{ $somehash{ $foo }->{ $bar } }, $x; }
||= basically says 'if the left-hand value isn't defined, assign the right-hand side to it'.
Chris
M-x auto-bs-mode
In reply to Re: push onto hash!
by lachoy
in thread push onto hash!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |