[Omaha.pm] ignoring undefined subroutines

Jay Hannah jay at jays.net
Wed Sep 8 19:09:15 CDT 2004


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.
--------------



More information about the Omaha-pm mailing list