Note: you have to create the anonymous reference -- you can't just push a value if the key doesn't exist.
In perl you can ;-)
use strict; use warnings; use Data::Dumper; my %hash; push @{$hash{key}}, 'value'; print Dumper \%hash; __END__ $VAR1 = { 'key' => [ 'value' ] };
This nice feature is called "autovivification" and is quite useful most of the time.
In reply to Re^2: multiple values for one key in hash
by moritz
in thread multiple values for one key in hash
by sovixi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |