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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -