in reply to Re^2: Function name in a variable, can't recall the concept
in thread Function name in a variable, can't recall the concept

> However, there is an exception:

More there are:

use strict; use warnings; sub tst { warn "tst($_[0]) called\n" } my $symbol="tst"; ($::{$symbol})->(1); &{$::{$symbol}}(2); (main->can($symbol))->(3); &{main->can($symbol)}(4);

C:/Perl_524/bin\perl.exe d:/exp/symbolic_references.pl tst(1) called tst(2) called tst(3) called tst(4) called

NB:

  • $::{...} is a shortcut for STASH lookup $main::{...} and returns a type-glob
  • ->can(...) returns a coderef

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Replies are listed 'Best First'.
    Re^4: Function name in a variable, can't recall the concept
    by ikegami (Patriarch) on Apr 15, 2019 at 00:54 UTC

      Those aren't really exceptions. Strict refs is only meant to stop you from accidentally using symbolic refs. (After all, you can always turn it off strict refs off if you want to use symbolic refs intentionally.) %:: and can only take symbol names, so they can't accidentally be used incorrectly.

        > Those aren't really exceptions.

        I was referring to "allowed under strict" requirement.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

          I know. A lot of things are allowed under strict refs (e.g. addition). That doesn't make them exceptions.