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 th

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 r

Re: Unknown level of hash

2005-03-29 Thread Markus Laire
Zhuang Li wrote: 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

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

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 Alexandre Jousset
Andrew Pimlott wrote: (You should be able to write the first one as ${fold_left { \${$_[0]}->{$_[1]} } \$hash, @a} = 1; but Perl complains for no reason I can see.) Of course, the '{}' operator is a hash ref generator, not an anonymous sub declarator as 'sub {}' is... But I declared fold_left

Re: Unknown level of hash

2005-03-29 Thread Andrew Pimlott
On Tue, Mar 29, 2005 at 11:30:49AM +0200, Alexandre Jousset wrote: > Andrew Pimlott wrote: > > > If you're feeling functional, > > > > ${fold_left(sub { \${$_[0]}->{$_[1]} }, \$hash, @a)} = 1; > > > > To get the value back out: > > > > fold_left { $_[0]->{$_[1]} } $hash, @a; > > > > Here i

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 Суханов Вадим
В сообщении от 29 Март 2005 01:08 Alexandre Jousset написал(a): > 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 p

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

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 level

Re: Unknown level of hash

2005-03-29 Thread Alexandre Jousset
Hello, Andrew Pimlott wrote: > If you're feeling functional, > > ${fold_left(sub { \${$_[0]}->{$_[1]} }, \$hash, @a)} = 1; > > To get the value back out: > > fold_left { $_[0]->{$_[1]} } $hash, @a; > > Here is fold_left: > > sub fold_left (&@) { > my $sub = shift; >