in reply to Re^11: 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.

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" ; }
  • Comment on Re^12: Function name in a variable, can't recall the concept (introspection with ->can )
  • Download Code

Replies are listed 'Best First'.
Re^13: Function name in a variable, can't recall the concept (introspection with ->can )
by ikegami (Patriarch) on Apr 19, 2019 at 18:55 UTC

    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.