Re: Unknown level of hash

Andrew Pimlott <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
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 is fold_left:
> >
> >     sub fold_left (&@) {
...
> >(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 with a prototype (&@), which should allow
dropping the "sub".  (And yes, in my actual program, I put this
declaration above the use, so the prototype is visible.)  It works for
the "get the value back out" example, but somehow it doesn't seem to
work inside the reference (${...}).  perlref doesn't say there are any
restrictions on what you can put inside ${...}, so I'm mystified.

Andrew
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.