Re: Unknown level of hash

Alexandre Jousset <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
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      |
  -|___|----------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.