in reply to Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it possible to use key/values of a Hash/Hash ref while it's being initialized?
by ikegami (Patriarch) on Sep 15, 2005 at 02:35 UTC |