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
      • ... Суханов Вадим
        • ... Alexandre Jousset
  • ... Ton Hospel
    • ... Yitzchak Scott-Thoennes
  • ... Yitzchak Scott-Thoennes
    • ... Alexandre Jousset
      • ... Yitzchak Scott-Thoennes
        • ... Alexandre Jousset
  • ... Andrew Pimlott
    • ... Alexandre Jousset
      • ... Andrew Pimlott
        • ... Alexandre Jousset
          • ... Alexandre Jousset
            • ... Andrew Pimlott
  • ... Zhuang Li
    • ... Jeff Yoak
    • ... Markus Laire
    • ... Luke Palmer
  • ... Zhuang Li
  • ... Zhuang Li

Reply via email to