davido has asked for the wisdom of the Perl Monks concerning the following question:
Consider the following code.
my %hash; @hash{ qw/ one two three / } = ( 1 .. 3 ); foreach ( qw/ one one three two one / ) { print $hash{$_},"\n"; }
Now this is going to look wierd, and seem like a terribly ugly construction. But those caviets aside, why can this not be done by using an anonymous hash as follows:
foreach ( qw/ one one three two one / ) { print ${@{ qw/ one two three / } = (1..3)}{$_},"\n"; }
Is there no way for an unnamed hash to be asigned its keys and values using slices and lists, while referring to one of its values?
Dave
"If I had my life to do over again, I'd be a plumber." -- Albert Einstein
|
|---|