Re: Unknown level of hash

2005-03-28 Thread Andrew Pimlott
On Mon, Mar 28, 2005 at 03:06:41PM -0800, Zhuang Li 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; If you're feeling f

Re: Unknown level of hash

2005-03-28 Thread Aaron Sherman
On Mon, 2005-03-28 at 18:43, Uri Guttman wrote: > > "ZL" == Zhuang Li <[EMAIL PROTECTED]> writes: > > ZL> Hi, given an array: @a = ('E1', 'E2', ..., 'En'); > ZL> Is there an easy way, hopefully one liner, to do the following without a > ZL> loop? If not, will Perl support this in Perl 6

Re: Unknown level of hash

2005-03-28 Thread Yitzchak Scott-Thoennes
On Tue, Mar 29, 2005 at 05:50:18AM +, Ton Hospel wrote: > I always found the code to do this WITH a loop quite funny in fact: > > my $work = \$hash; > $work = \$$work->{$_} for @a; > $$work = 1; Ha ha ha :)

Re: Unknown level of hash

2005-03-28 Thread Yitzchak Scott-Thoennes
On Mon, Mar 28, 2005 at 03:06:41PM -0800, Zhuang Li 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; To read from such a se

Re: Unknown level of hash

2005-03-28 Thread Ton Hospel
I always found the code to do this WITH a loop quite funny in fact: my $work = \$hash; $work = \$$work->{$_} for @a; $$work = 1;

Re: Unknown level of hash

2005-03-28 Thread Uri Guttman
> "AS" == Aaron Sherman <[EMAIL PROTECTED]> writes: AS> On Mon, 2005-03-28 at 18:43, Uri Guttman wrote: >> > "ZL" == Zhuang Li <[EMAIL PROTECTED]> writes: >> ZL> Hi, given an array: @a = ('E1', 'E2', ..., 'En'); ZL> Is there an easy way, hopefully one liner, to do the following

Re: Unknown level of hash

2005-03-28 Thread Alexandre Jousset
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', '

RE: Unknown level of hash

2005-03-28 Thread Zhuang Li
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'], ...

RE: Unknown level of hash

2005-03-28 Thread Jeff Yoak
I meant more that my answer was more "fun" than "useful." I can't imagine a reason one wouldn't prefer a loop to an eval. :-) On Mon, 2005-03-28 at 16:00, Zhuang Li wrote: > Yes. I think it's both useful and fun. I was thinking something similar > to > @[EMAIL PROTECTED] = map{1} @a; Well...

Re: Unknown level of hash

2005-03-28 Thread Vladi Belperchinov-Shabanski
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 ); bot

RE: Unknown level of hash

2005-03-28 Thread Zhuang Li
Yes. I think it's both useful and fun. I was thinking something similar to @[EMAIL PROTECTED] = map{1} @a; But getting "$hash->{E1}->{E2}->...->{En} = 1;" instead of "$hash{E1} = 1; ... $hash{En} =1;". What I'd really like to do is: Given @a = ('E1', 'E2', ..., 'En'); @b = ('K1', 'K2',

Re: Unknown level of hash

2005-03-28 Thread Uri Guttman
> "ZL" == Zhuang Li <[EMAIL PROTECTED]> writes: ZL> Hi, given an array: @a = ('E1', 'E2', ..., 'En'); ZL> Is there an easy way, hopefully one liner, to do the following without a ZL> loop? If not, will Perl support this in Perl 6? ZL> $hash->{E1}->{E2}->...->{En} = 1; i think perl6

Re: Unknown level of hash

2005-03-28 Thread Jeff Yoak
On Mon, 2005-03-28 at 15:06, Zhuang Li 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; use Data::Dumper;

Unknown level of hash

2005-03-28 Thread Zhuang Li
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