Vladi,

I like the 'hidden loop' with map solution better. As you can probably
tell, just get:
$hash->{E1}->{E2}->...->{En} = 'v1' is not that meaningful but this is:
Given:
$a = [
                ['E11', 'E12', ..., 'E1n'],
                ['E21', 'E22', ..., 'E2n'],
                ...
                ['Em1', 'Em2', ..., 'Emn'],
        ];

$b = ['V1', 'V2', ..., 'Vm'];


Get(without loops but hidden loop is OK):

$hash->{E11}->{E12}->...->{E1n} = 'V1';
$hash->{E21}->{E22}->...->{E2n} = 'V2';
...
$hash->{Em1}->{Em2}->...->{Emn} = 'Vm';


john


> -----Original Message-----
> From: Vladi Belperchinov-Shabanski [mailto:[EMAIL PROTECTED]
> Sent: Monday, March 28, 2005 4:02 PM
> To: fwp@perl.org
> Subject: Re: Unknown level of hash
> 
> 
> 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...
> 

Reply via email to