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

Works with strict and doesn't require an eval()
sub foo { print "in foo()\n"; } my $func_name = "foo"; &{\&{$func_name}}(); __output__ in foo()

HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Re: variable function thingy
by rir (Vicar) on Oct 18, 2002 at 20:17 UTC
    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"}; }
      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.