in reply to Re^2: Hash assignments using map
in thread Hash assignments using map
the first statement takes the elements from the array @keys, increments them and adds to the hash %hash.
first point is, you only have letters, no numbers, so Perl won't "increment" them, and will just add them as they already are to the hash.
secont point, the hash takes two elements to populate a key-value pair. for example, a hash %h = (a => 1, b => 2, c => 3) could also be written as %h = qw{a 1 b 2 c 3}.
the second statement takes each element from the array as a key of the hash, incrementing its value each time it's processed (which means if you have twice the element "a" in the array, the value of the key "a" in the hash will be 2 etc). if you want to use map to do that, it'd like map { $hash{$_}++ } @keys.
first point is, you only have letters, no numbers, so Perl won't "increment" them, and will just add them as they already are to the hash.
secont point, the hash takes two elements to populate a key-value pair. for example, a hash %h = (a => 1, b => 2, c => 3) could also be written as %h = qw{a 1 b 2 c 3}.
the second statement takes each element from the array as a key of the hash, incrementing its value each time it's processed (which means if you have twice the element "a" in the array, the value of the key "a" in the hash will be 2 etc). if you want to use map to do that, it'd like map { $hash{$_}++ } @keys.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Hash assignments using map
by chargrill (Parson) on Feb 24, 2007 at 16:47 UTC | |
by mk. (Friar) on Feb 24, 2007 at 16:56 UTC |
In Section
Seekers of Perl Wisdom