in reply to Function name in a variable, can't recall the concept

Today is not my day. When it was mentioned that what I demonstrated in my examples wouldn't work under use strict; I went back and looked at the code again and realized my example was wrong. Here's what I am really doing:
my $funcname = ( $someCondition ? 'foo' : 'bar' ); $someObject->$funcname($arg1, $arg2);
It's not "Function name in variable", it's "Method name in variable", and a relevant reference to same is https://perldoc.perl.org/perlobj.html#Method-Call-Variations

Replies are listed 'Best First'.
Re^2: Function name in a variable, can't recall the concept
by VinsWorldcom (Prior) on Apr 02, 2019 at 21:28 UTC

    That's OK, from examples above:

    use strict; use warnings; package Object; sub new { return bless \{} } sub foo { printf "hello foo = %s\n", ( caller(0) )[3]; } sub bar { printf "hello bar = %s\n", ( caller(0) )[3]; } package main; my $someObject = Object->new(); my $someCondition = 0; my $funcname = ( $someCondition ? 'foo' : 'bar' ); $someObject->$funcname($funcname); $someCondition = 1; $funcname = ( $someCondition ? 'foo' : 'bar' ); $someObject->$funcname($funcname);