in reply to Re^10: Function name in a variable, can't recall the concept (introspection with ->can )
in thread Function name in a variable, can't recall the concept

\&$name works even under strict refs. No need to turn it off.

You need to return something (undef?) in the else case.

  • Comment on Re^11: Function name in a variable, can't recall the concept (introspection with ->can )
  • Select or Download Code

Replies are listed 'Best First'.
Re^12: Function name in a variable, can't recall the concept (introspection with ->can )
by Veltro (Hermit) on Apr 19, 2019 at 18:35 UTC
    \&$name works even under strict refs. No need to turn it off.

    Perfect, makes the code even simpler

    You need to return something (undef?) in the else case.

    Good question actually. My tests didn't seem to need it...

    sub test { ... } ; ... if ( my $s = get_sub_by_name( "", "test" ) ) { $s->() ; } else { print "No\n" ; }

      It wasn't a question. Your code relies on the result of an if statement with a false conditional being that false value, and it shouldn't.