[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] ignoring undefined subroutines
On Sep 7, 2004, at 3:33 PM, Terry wrote:
Thanks Jay, worked fine. Thinking outside the box with regards to
scripting isn't on my resume for a good reason.
"I think I'm going to need a bigger box." -- Taco Bell Chihuaha
AUTOLOAD is very slick. You can program anything you want to have
happen if an undefined sub/method is called. Like if you had 10
header_xxx sub/methods that were almost all exactly the same, you could
use AUTOLOAD to call a single, central sub/method, passing in an
argument for the tweak (instead of having to explicitly declare 10
sub/methods)... See "perldoc perltoot".
Looks like this would work for you too?
&{"header_$who"} if (defined &{"header_$who"});
My test:
[jhannah-mac:~] jhannah% cat j.pl
#!/usr/bin/perl
my @subs = qw( one two three );
foreach (@subs) {
&$_ if (defined &$_);
}
sub one { print "1\n"; }
sub three { print "3\n"; }
[jhannah-mac:~] jhannah% ./j.pl
1
3
HTH,
j