Next Tricks of the Wizards 98

Simple AUTOLOAD Example

        @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";
           }
        }
        blug(...);

it just calls blue for you with the same arguments as if nothing was wrong



Next Copyright © 2003 M. J. Dominus