in reply to Declare and slice-initialize hash in one statement?
Your map solution is as close as you'll come, but you're right, if all you want to do is initialize a slice it's too longwinded.
You cannot declare a hash, and initialize a slice at the same time. Just do it this way:
my %hash; @hash{ list of keys } = ( list of values );
...where list of keys and list of values are obviously left up to you to fill in the blanks. BTW: Don't do the "no strict" method. Here's why. That version results in %hash being created as a package global, instead of as a lexical, and there is a big difference.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Declare and slice-initialize hash in one statement?
by Perl Mouse (Chaplain) on Oct 27, 2005 at 16:31 UTC |