开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜