in reply to Re: Can't Reference a Sub by Variable when using Strict
in thread Can't Reference a Sub by Variable when using Strict

Did you try your code under strict? There's a symbolic reference of the same kind in the second line.

  • Comment on Re^2: Can't Reference a Sub by Variable when using Strict

Replies are listed 'Best First'.
Re^3: Can't Reference a Sub by Variable when using Strict
by broquaint (Abbot) on Oct 04, 2004 at 07:41 UTC
    Creating symbolic references to subroutines is quite valid under strictures e.g
    use strict; sub foo { print "It's all good."; } my $subref = \&{ "foo" }; &$subref; __output__ It's all good.
    HTH

    _________
    broquaint

      That's a bug not a feature :-)

      C:\>perl -MO=Deparse test.pl sub foo { print q[It's all good.]; } my $subref = \&{'foo';}; &$subref;
Re^3: Can't Reference a Sub by Variable when using Strict
by Fletch (Bishop) on Oct 04, 2004 at 14:13 UTC
    freebie:~ 1085> cat bar + 10:08:26 use strict; my %lists; for my $i ( keys %lists ) { my $coderef = \&{ $i }; &{ $coderef }(); } freebie:~ 1086> perl -c bar + 10:08:28 bar syntax OK

    This is perfectly valid due to the goto exception I mentioned. If you read perldoc strict:

    There is one exception to this rule: $bar = \&{'foo'}; &$bar; is allowed so that "goto &$AUTOLOAD" would not break unde +r stricture.

      So it is; thanks!