gri6507 has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my @q = (\&abc, \&def); my $msg; my $param = "hhhhhh"; foreach my $q (@q) { if (defined(&$q)) { $msg .= $q->($param); } else { $msg .= "cannot call $q\n"; } } print $msg; sub abc { my $q = shift; return "hello from ABC($q)\n"; }
This works correctly for the abc() routine which does exist. Moreover, this code correctly identifies that def() routine does not exist. However, when I print that out, all I get is cannot call CODE(0xac1a40).Is there a way for me to instead print out cannot call def?
Thanks as always!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting the name of sub from sub reference
by BrowserUk (Patriarch) on Oct 14, 2010 at 17:09 UTC | |
|
Re: Getting the name of sub from sub reference
by moritz (Cardinal) on Oct 14, 2010 at 16:46 UTC | |
by Anonymous Monk on Oct 14, 2010 at 18:40 UTC | |
|
Re: Getting the name of sub from sub reference
by morgon (Priest) on Oct 14, 2010 at 16:40 UTC | |
|
Re: Getting the name of sub from sub reference
by kcott (Archbishop) on Oct 14, 2010 at 18:26 UTC |