in reply to Throw compilation error(or warning) if duplicate keys are present in hash

use strict; use warnings; my %hash = ("one" => "1", "two" => "2", "one" => "3", ); foreach my $key ( keys %hash ) { print $key, " => ", $hash{$key}, "\n"; }
output
one => 3 two => 2
unable to track the dublicate key.filtration done by perl itself
nice point by i_love_perl

Replies are listed 'Best First'.
Re^2: Throw compilation error(or warning) if duplicate keys are present in hash
by ikegami (Patriarch) on Nov 25, 2011 at 04:02 UTC
    %hash = EXPR;
    does something like
    my @anon = LIST; %hash = (); while (@anon) { my $k = shift(@anon); my $v = shift(@anon); $hash{$k} = $v; }

    So if you have two values for the same key, the latter prevails.

    (There's no actual @anon created; the stack is used.)