passing parameters with perl using reflection
I have the following Perl module:
package module
sub 开发者_如何学Pythontest1{
my @data=@_
print @data;
}
When I call this module from a Perl script using:
my $test='test1';
my $full_name = "Module::" . $test;
my @data=(1,2,3)
no strict 'refs';
$full_name->(@data);
I get no result on stdout but I expected 1,2,3. Could someone explain why?
It sounds like you are not setting up your module properly.
Running the following self contained script produces the correct result:
{package Module;
sub test1 {print "test1: @_\n"}
}
my $test = 'test1';
my $full_name = 'Module::'.$test;
my @data = (1, 2, 3);
no strict 'refs';
$full_name->(@data); # test1: 1 2 3
It is hard to tell without seeing exactly what you have, but chances are you have forgotten to include the package Module;
line at the top of your module. The package is not implicitly set via the file name, you must declare it at the top of the file.
精彩评论