Next | Tricks of the Wizards | 98 |
@funcs = qw(red yellow blue);
sub red { ... } # etc.
sub AUTOLOAD { my ($package, $function) = ($AUTOLOAD =~ /(.*)::(.*)/); my $correct = approximate_match($function, \@funcs); if (defined &$correct) { return &$correct(@_); } else { die "Function $function unknown; try [@funcs]\n"; } }
Now if you do
blug(...);
it just calls blue for you with the same arguments as if nothing was wrong
Inside of AUTOLOAD, @_ contains the regular function arguments
Next | Copyright © 2003 M. J. Dominus |