Re: Unknown level of hash

2005-03-29 Thread Alexandre Jousset
Yitzchak Scott-Thoennes wrote: To set it, you need to just do the same thing except that at each step instead of keeping the hash element, you keep a reference to it: $entryref = \$hash; $entryref = \$$entryref-{$_} for @a; $$entryref = 1; Note that this will create hashrefs at any undefined

Re: Unknown level of hash

2005-03-29 Thread Yitzchak Scott-Thoennes
On Tue, Mar 29, 2005 at 11:45:01AM +0200, Alexandre Jousset wrote: Yitzchak Scott-Thoennes wrote: To set it, you need to just do the same thing except that at each step instead of keeping the hash element, you keep a reference to it: $entryref = \$hash; $entryref = \$$entryref-{$_} for @a;

Re: Unknown level of hash

2005-03-29 Thread Alexandre Jousset
Yitzchak Scott-Thoennes wrote: I'm sorry but that doesn't work as is on my system: Not a HASH reference at x.pl line 9.. Works for me. Can you show the actual code you are trying? In fact I made a mistake. Sorry again, you're right ! :-) -- \^/ -/ O

Re: Unknown level of hash

2005-03-29 Thread Alexandre Jousset
wrote: [snip code...] gives: $VAR1 = { 'E1' = { 'E2' = { 'E3' = { 'En' = 1 } }, 'E3' = {

Re: Unknown level of hash

2005-03-29 Thread Alexandre Jousset
Alexandre Jousset wrote: Andrew Pimlott wrote: (You should be able to write the first one as ${fold_left { \${$_[0]}-{$_[1]} } \$hash, @a} = 1; Is it a copy/paste or a retype ? Because there's a comma missing after the first closing brace... but Perl complains for no reason I can see.) --

Re: Unknown level of hash

2005-03-29 Thread Andrew Pimlott
On Tue, Mar 29, 2005 at 06:42:41PM +0200, Alexandre Jousset wrote: Alexandre Jousset wrote: Andrew Pimlott wrote: (You should be able to write the first one as ${fold_left { \${$_[0]}-{$_[1]} } \$hash, @a} = 1; Is it a copy/paste or a retype ? Because there's a comma missing

Re: Unknown level of hash

2005-03-29 Thread Luke Palmer
Zhuang Li writes: 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;. Yeah, like this: %hash{dims @a} = (1) xx Inf; What I'd really like to

RE: Unknown level of hash

2005-03-29 Thread Zhuang Li
-Original Message- From: Luke Palmer [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 29, 2005 5:43 AM To: Zhuang Li Cc: Jeff Yoak; fwp@perl.org; perl6-language@perl.org Subject: Re: Unknown level of hash Zhuang Li writes: Yes. I think it's both useful and fun. I was thinking

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

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; my @x = qw/a

RE: Unknown level of hash

2005-03-28 Thread Zhuang Li
To: Zhuang Li Cc: fwp@perl.org Subject: Re: Unknown level of hash 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

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 );

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... that's

RE: Unknown level of hash

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

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 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 without a ZL loop? If

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 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 series of

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