我知道我想做的这种事情曾经在 5.8 中工作过。难道我做错了什么?有没有办法在 Perl 5.10 中回到那里?
这是模块:
package TableMod;
use base qw<Exporter>;
our @EXPORT_OK = qw<mod_table>;
use Data::Dumper;
sub mod_table (\%@) { print Dumper( @_ ); }
1;
这是脚本:
use strict;
use warnings;
use Data::Dumper;
use Test::More tests => 4;
sub mod_table_here (\%@) {
print Dumper( @_ );
}
use_ok( 'TableMod', 'mod_table' );
can_ok( __PACKAGE__, 'mod_table' );
is( prototype( \&mod_table_here ), '\\%@'
, q/prototype( \&mod_table_here ) = '\%@'/
);
is( prototype( \&mod_table ), prototype( \&mod_table_here )
, 'prototypes ARE the SAME!'
);
my %table = qw<One 1>;
mod_table_here %table => ( 1, 2, 3, 4 );
#mod_table %table => ( 1, 2, 3, 4 );
mod_table( %table, 1, 2, 3, 4 );
我所要做的就是取消最后一行的注释,我得到:
Useless use of modulus (%) in void context at - line 17.
Useless use of a constant in void context at - line 17.
Useless use of a constant in void context at - line 17.
Useless use of a constant in void context at - line 17.
Bareword "mod_table" not allowed while "strict subs" in use at - line 17.
它不抱怨本地潜艇,但对进口潜艇失去了理智。最重要的是,尽管测试告诉我我已经导入了“mod_table”,但现在严格感到困惑的是它是一个裸词!
不仅如此,尽管测试告诉我原型是相同的,但我不能%table
作为 hashref 传递给导入的 sub 。即使我使用最后一行所示的常规语法也不行。
我得到的是:
1..4
ok 1 - use TableMod;
ok 2 - main->can('mod_table')
ok 3 - prototype( \&mod_table_here ) = '\%@'
ok 4 - prototypes ARE the SAME!
$VAR1 = {
'One' => '1'
};
$VAR2 = 1;
$VAR3 = 2;
$VAR4 = 3;
$VAR5 = 4;
$VAR1 = 'One';
$VAR2 = '1';
$VAR3 = 1;
$VAR4 = 2;
$VAR5 = 3;
$VAR6 = 4;