The value of key1 has to be laying around somewhere?!?
No, but you can bookmark it if you want:
my %hash = map { my $foo; $_ => { key1 => $foo = 'longstring'.$_.'more', key2 => alter( $foo ), } } @list;
That would work, though I am not sure I would recommend it. A two-stage approach would/might be cleaner, I think:
my %hash = map { my $foo = { key1 => 'longstring'.$_.'more' }; $foo->{"key2"} = alter( $foo->{"key1"} ); $_ => $foo; } @list;
Actually, now that I've written both, I can't decide which is cleaner.
In reply to Re: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
by fishbot_v2
in thread Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
by shiza
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |