Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Hash assignments using mapby johngg (Canon) |
on Feb 24, 2007 at 18:16 UTC ( [id://601900]=note: print w/replies, xml ) | Need Help?? |
If you are trying to initialise a hash with four keys ("a" to "d") each with a value of 1 using map you need to pass your four keys into the map but pass eight things out the other side, 'a', 1, 'b', 1, 'c', 1, 'd', 1. This is because a hash with four key/value pairs will flatten to a list of eight elements. You can do it like this.
Your loop alternative could be written
Another alternative is to use a hash slice
I hope this is of use. Cheers, JohnGG
In Section
Seekers of Perl Wisdom
|
|