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

Cute. Is this a Perl bug?

Either way a simple no strict 'refs'; seems like the way to go.

sub foo { print "in foo\n"; } { no strict 'refs'; &{"foo"}; }

Replies are listed 'Best First'.
Re: Re: Re: Re: variable function thingy
by broquaint (Abbot) on Oct 19, 2002 at 19:09 UTC
    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

      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