On 4/7/06, Roger Mayfield <[EMAIL PROTECTED]> wrote:
> How could I write a script that could anonymously accept user written
> modules that are listed in a text file? reading from a text file I get,
> but where would I start on loading the modules dynamically like that?
>
>
> Roger Mayfield
snip

Well, in Perl TIMTOWTDI.  I like to use eval like this:

my $all_loaded = 1;
while (my $module = <FH>) {
    unless (eval "use $module; 1") {
        warn "Could not load $module: $@";
        $all_loaded = 0;
    }
}
die "An error occured while loading user defined modules." unless $all_loaded;

Note that this is not the best idea in the world though.  You leave
yourself open to injection attacks (they could put "Archive::Zip;
system('cp some_sensitive_file /tmp/foo; chmod 777 /tmp/foo');" in the
file).  You should only allow this if the script is going to run as
the same user who creates the file (and the file should only have
write permissions for the user).  You might also consider turning on
the taint pragma and use regular expressions to untaint the module
names.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to