Re: Unknown level of hash

[email protected] (Vladi Belperchinov-Shabanski)
Newsgroups perl.fwp
Organization CSA
Message-ID <[email protected]>
two solutions:

obvious one:

   @a = ( 'E1', 'E2', 'E3', 'En' );
   eval '$a{ ' . join( ' }{ ', @a ) . '} = 1';
   print Dumper( \%a );

Interpreters rule :)

and 'hidden loop' one:

   @a = ( 'E1', 'E2', 'E3', 'En' );
   $a = 1;
   map{ $a = { $_ => $a } } reverse @a;
   print Dumper( $a );

both print this:

$VAR1 = {
          'E1' => {
                    'E2' => {
                              'E3' => {
                                        'En' => 1
                                      }
                            }
                  }
        };

cheers!

P! Vladi.

On Mon, 28 Mar 2005 15:06:41 -0800
"Zhuang Li" <[email protected]> wrote:

> Hi, given an array: @a = ('E1', 'E2', ..., 'En'); 
> 
>  
> 
> Is there an easy way, hopefully one liner, to do the following without a
> loop? If not, will Perl support this in Perl 6?
> 
>  
> 
> $hash->{E1}->{E2}->...->{En} = 1;
> 
>  
> 
>  
> 
> Thanks,
> 
>  
> 
> john
> 
> 


-- 
Vladi Belperchinov-Shabanski <[email protected]> <[email protected]>
http://cade.datamax.bg/   pgp/gpg key id: 6F35B214 (pgp.mit.edu)
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFCSJrlkBm4tG81shQRAuCOAJ9fliJ5Isqz6ST+bI9BQ+PvznyoRQCfdt8/
wwjB522yJnQl9jXtPzo1T1E=
=ohF/
-----END PGP SIGNATURE-----
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.