Loading and using modules using eval

From: Papo Napolitano (papo_at_dosalcubo.com)
Date: 01/23/04


To: beginners@perl.org
Date: Fri, 23 Jan 2004 18:23:10 -0300

Hi all,

I have this piece of code:

my @modules = (
 'Module1', 'Module2', 'Module3',
 'ModuleX', 'ModuleY', 'Blah',
);
my $param1 = "whatever";
my $param2 = 0;
for my $module (@modules) {
  $param2++;
  eval("require $module");
  if ($@) {
    print "$module Not found\n";
  } else {
    eval("&${module}::process('$param1', '$param2')");
  }
}

And it's working, but I wonder if there's any cleaner/better way to do this.
The main idea is to have a XML file like this:

<xml>
  <file source="file1.txt" module="TextFile" parameters="1"/>
  <file source="file2.csv" module="TextFile" parameters="2"/>
  <file source="file3.xml" module="XMLFile" parameters="this and that"/>
</xml>

To tell me I have to do:

&TextFile::process('file1.txt', '1');
&TextFile::process('file2.csv', '2');
&XMLFile::process('file3.xml', 'this and that');

Got it? ;-)

Thanks!



Relevant Pages

  • Re: User global parameters - not through ASPs Session object
    ... Is DB or XML file on Server - the only tricks? ... Since the read/write operations of param1 and param2 are relatively ... [Microsoft MVP - FrontPage] ...
    (microsoft.public.scripting.vbscript)
  • Re: User global parameters - not through ASPs Session object
    ... Is DB or XML file on Server - the only tricks? ... of concurrent users. ... Since the read/write operations of param1 and param2 are relatively ...
    (microsoft.public.scripting.vbscript)
  • Re: VB und C# Spezi Frage
    ... >> Public Overloads Sub Foo(ByVal Param1 As String) ... >> Public Overloads Sub Foo(ByVal Param2 As String) ... 'Param2' = Nothing ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Designfrage
    ... Ansonsten teste das Timingverhalten doch Mal wenn du dein Parameter als TComponent-Abkömmling implementierst. ... TAppParams = class ... property Param1: ... property Param2: ...
    (de.comp.lang.delphi.misc)
  • Tomahawk and SaveState
    ... mainBean is a bean which contains: ... when the param1 value changes, the param2 don't change even if the ... mainBean. ...
    (comp.lang.java.programmer)