my %hash; # Assume a loop here that creates keys and values... my $key = 'alphabet'; my $letters = ['abc','def']; if (exists $hash{$key}) { my @letters_array = $hash{$key}; push @letters_array, $letters; my $new_val = [@letters_array]; $hash{$key} = $new_val; } else { $hash{$key} = $letters; } # Then check for "duplicate" keys (ie. a key with more than one value) +. for $key (keys %found_mod) { if (ref($found_mod{$key}[0]) eq 'ARRAY') { print "This key -- $key -- has more than one value!\n"; } }
In reply to Hashes with "duplicate" keys by jacques
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |