Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Adding values from an array to a hash

by blazar (Canon)
on Oct 12, 2006 at 10:29 UTC ( [id://577799] : note . print w/replies, xml ) Need Help??


in reply to Adding values from an array to a hash

Now I think that this setup is really annoying, easpecially as I would like rewrite it so that every value is counted to represent how often a location has been added. Is there a way to add onto the old hash instead of completely rewriting it?

I'm not really sure if I understand your question, but you probably either want

%locations=(%locations, map {$_ => 1} @locations);

or

$locations{$_}++ for @locations;