On Jan 23, 2004, at 1:23 PM, Papo Napolitano wrote: [..]
<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');
Why not try something a bit more vanilla where one does the
use SomeModuleHere;
for all the modules you want to use. Then you can use the no strict refs option IF you really want to do the strictly functional approach.
I do not think that
eval("&${module}::process('$param1', '$param2')");
will do what you want it to do.
IF the Text::process and XML::process functions are things that you are building out you may want to think about the idea of doing the perl oo-ish aproach, as
$foo->showMe($line);
will work without requiring the no strict refs.
ciao drieux
---
Some code to play around with would be:
#!/usr/bin/perl -w
use strict;
my ($foo, $line) ;
while(<DATA>){
chomp;
/^([\w:]+)\s+(.*)/;
($foo, $line) = ($1,$2);
# this assumes that the Package is External
# require "$foo.pm" if (!exists($INC{"$foo.pm"}));
# the way that will work by indirection
#$foo->showMe($line);
my $code = "${foo}::showMe";
no strict 'refs';
$code->($line);
# does not invoke the code
#eval{ &${foo}::showMe($line) };
if ($@)
{
print "Error: had \$foo -> $foo\n\t\$line -> [EMAIL
PROTECTED]";
}
}
print "and now a Procecural call:\n" ;
Foo::showMe("Procedural\n$line\n");
BEGIN {
package Foo::Bar;
#------------------------
#
sub showMe
{
#my $me = shift if ( $_[0] eq __PACKAGE__);
my ($line) = @_;
print $line;
print "\n" unless $line =~ /\n/gim;
} # end of showMe
1;
package Foo;
#------------------------
#
sub showMe
{
#my $me = shift if ( $_[0] eq __PACKAGE__ or
# ref($_[0]) eq __PACKAGE__ );
my ($line) = @_;
print "foo sees:\n\t $line\n";
} # end of showMe
1; # so that the 'use Foo::Bar'
# will know we are happy
} # end begin
__DATA__
Foo word up
Foo::Bar not that one.
Foo This is a Happy Line
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
