BigLug has asked for the wisdom of the Perl Monks concerning the following question:
1. Is there a 'best' or simple way to load all the modules? I figure an evaled require in a loop. However I don't want to eval user input. Can anyone suggest a better way to do it?
2. Once they're loaded, how should I access them? At several points in my code I want to use the hash. One thought was to use eval to import the hash at load time, however I'm still sending user input to eval!:foreach my $cc (@country_code) { eval( "require MyModule::$cc" ); croak("Unable to locate MyModule::$cc") if $@; }
However I'd prefer not to import it all if I can. I'd prefer to store a reference to the hash in my object or even to grab the data as needed. But I don't want to fill my module with eval()s Thoughts and comments welcome.foreach my $cc (@country_code) { eval( "require MyModule::$cc" ); croak("Unable to locate MyModule::$cc") if $@; push( @{$self->{data}}, { eval( "\%MyModule::$cc::Hash" ) } ); }
Update: I can't validate the user input with known values. However I can validate it using a regex: croak if $cc !~ /^[a-z]{2}$/i
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically wrapping multiple modules
by kvale (Monsignor) on Apr 19, 2004 at 08:56 UTC | |
by BigLug (Chaplain) on Apr 19, 2004 at 09:28 UTC | |
by eserte (Deacon) on Apr 19, 2004 at 10:53 UTC | |
|
Re: Dynamically wrapping multiple modules
by broquaint (Abbot) on Apr 19, 2004 at 17:56 UTC | |
|
Re: Dynamically wrapping multiple modules
by ysth (Canon) on Apr 19, 2004 at 15:48 UTC | |
|
Re: Dynamically wrapping multiple modules
by Ryszard (Priest) on Apr 20, 2004 at 08:40 UTC |