in reply to Re: Re: Re: variable function thingy
in thread variable function thingy

Cute. Is this a Perl bug?
Nope, this is perfectly legal. It just creates a reference, which is then dereferenced and since it's a normal reference (see. not symbolic) strict doesn't have a problem with it. I originally saw this funky trick in a node by gbarr.
HTH

_________
broquaint

  • Comment on Re: Re: Re: Re: variable function thingy

Replies are listed 'Best First'.
(Re:)+ variable function thingy
by rir (Vicar) on Oct 19, 2002 at 20:27 UTC
    use strict; sub foo { print "fooing\n"; &{\&{"foo"}}; \&{"foo"}; &{"foo"}; # not following the strictures

    Please elucidate.

    On what basis are you claiming this is "perfectly legal". I've just gone through the Camel and your referenced pages and find nothing to support this claim.

    My opinion:

    All of the above constructs should be legal if the first is. \& is not a single op. The \ operates on whatever follows. The & is part of the function name.

      On what basis are you claiming this is "perfectly legal"
      On the basis that it parses correctly and runs correctly without so much as a peep from strict or warnings. I'd say that's a pretty solid basis.
      I've just gone through the Camel and your referenced pages and find nothing to support this claim.
      Just because it isn't in the Camel doesn't mean that it's not in perl, it just means that it is so obscure it was left out of the Camel for the safety and sanity of perl programmers the world over ;)
      HTH

      _________
      broquaint

        That is a completely lame reason. Recommending the usage of undocumented/undefined features is bad. Claiming the legality of undocumented/undefined behaviour is sub-optimal.

        But I was wrong.1   broquaint is correct, the construct:

        use strict 'refs';
        my $v = \&{'foo'};Is legal.

        It is documented as the as the one exceptional case necessary to let AUTOLOAD run under stricture.

        Thanks for the education.


        1 This is emblazoned so you won't miss the info re: strict, not because an error of mine is noteworthy per se. I wish.

        Updated as broquaint tells me I misrepresented his words.