M
martin
This is probably a simpel question, I am trying to intialize a large
hash, the keys are single word strings and the values are numeric.
I am wondering if there is a simple way to use two arrays to assign to
values and keys respectively, as opposed to the usual means of
let's say
my %citieshash {'key1', value1, 'key2', value2, ........}
if I have a large hash of 100 entries, let say this becomes awkward
specially if I want to set all values to zero, initially.
I tried %cities = ( );
and then used a loop to scan from a file the keys, it works fine if all
city names are present , but if not all keys/cities are present, and I
want to do addition of values with += the compiler starts complaining.
Is there a single shot approach to zero initialization and also to
setting key values using an existing array.
something like
(keys %citieshash) = @some_array <-- I know this one does not work
Thanks.
hash, the keys are single word strings and the values are numeric.
I am wondering if there is a simple way to use two arrays to assign to
values and keys respectively, as opposed to the usual means of
let's say
my %citieshash {'key1', value1, 'key2', value2, ........}
if I have a large hash of 100 entries, let say this becomes awkward
specially if I want to set all values to zero, initially.
I tried %cities = ( );
and then used a loop to scan from a file the keys, it works fine if all
city names are present , but if not all keys/cities are present, and I
want to do addition of values with += the compiler starts complaining.
Is there a single shot approach to zero initialization and also to
setting key values using an existing array.
something like
(keys %citieshash) = @some_array <-- I know this one does not work
Thanks.