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...
                                                    

Attachment: pgp13Hzk2Nl3I.pgp
Description: PGP signature

  • ... Zhuang Li
    • ... Jeff Yoak
    • ... Uri Guttman
      • ... Aaron Sherman
        • ... Uri Guttman
    • ... Vladi Belperchinov-Shabanski
      • ... Alexandre Jousset
        • ... Суханов Вадим
          • ... Alexandre Jousset
    • ... Ton Hospel
      • ... Yitzchak Scott-Thoennes
    • ... Yitzchak Scott-Thoennes
      • ... Alexandre Jousset
        • ... Yitzchak Scott-Thoennes
          • ... Alexandre Jousset
    • ... Andrew Pimlott

Reply via email to