Re: Unknown level of hash
[email protected] (Alexandre Jousset)
| Newsgroups | perl.fwp |
|---|---|
| Message-ID | <[email protected]> |
Hey all...
Vladi Belperchinov-Shabanski wrote:
[snip...]
> and 'hidden loop' one:
>
> @a = ( 'E1', 'E2', 'E3', 'En' );
> $a = 1;
> map{ $a = { $_ => $a } } reverse @a;
> print Dumper( $a );
The problem with this one is that by doing this you destroy existing
hashes. e.g. :
@a = ( 'E1', 'E2', 'E3', 'En' );
$a = 1;
map{ $a = { $_ => $a } } reverse @a;
@a = ( 'E1', 'Ex', 'Ey', 'Ez' );
$a = 1;
map{ $a = { $_ => $a } } reverse @a;
print Dumper( $a );
gives :
$VAR1 = {
'E1' => {
'Ex' => {
'Ey' => {
'Ez' => 1
}
}
}
};
thus destroying the 'E2' entry (as well as all potential existing
ones). Too bad, it was an elegant solution...
BTW I already searched for this problem before and have not found
anything interesting besides the 'eval'.
A+
--
\^/
-/ O \----------------------------------------
| |/ \| Alexandre (Midnite) Jousset |
-|___|----------------------------------------