in reply to variable function thingy

$var="post"; eval "&$var";

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

      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