[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] ignoring undefined subroutines
On Sep 8, 2004, at 4:57 AM, Hugh Jarce wrote:
if (exists($main::{"header_$who"})) {
&{$main::{"header_$who"}};
How would you know that header_$who is a sub and not just an errant
scalar defined in the package "main"?
The code below blows up unless you take the $two = line out...
j
-----------
% cat j.pl
#!/usr/bin/perl
my @subs = qw( one two three );
$two = "kaboom!"; # Comment this line out and everything is fine
foreach (@subs) {
if (exists($main::{$_})) {
&$_;
}
}
sub one { print "1\n"; }
sub three { print "3\n"; }
% ./j.pl
1
Undefined subroutine &main::two called at ./j.pl line 7.
--------------