Next Tricks of the Wizards 107

Autoloading From a File

        sub AUTOLOAD {
           my $file = $AUTOLOAD;
           $file =~ s{::}{/}g;
           $file = "/src/app/autoloaded/$file.al";
           open my $fh, "< $file" 
             or croak "Couldn't load code from $file: $!; aborting";
           my $code;
           { local $/; $code = <$fh> }
           *$AUTOLOAD = eval $code;
           goto &$AUTOLOAD;
        }


Next Copyright © 2003 M. J. Dominus