arrays - Why does my first hash value disappear in Perl? -
why hash remove first value apple:2
when print output?
use warnings; use strict; use data::dumper; @array = ("apple:2", "pie:4", "cake:2"); %wordcount; our $curword; our $curnum; foreach (@array) { ($curword, $curnum) = split(":",$_); $wordcount{$curnum}=$curword; } print dumper (\%wordcount);
perl hash can have unique keys,
$wordcount{2} = "apple";
is later overwritten
$wordcount{2} = "cake";
Comments
Post a Comment