我正在模块化我的代码,但是当我移出sub
它的原始模块时,我收到以下错误:
Couldn't load application from file "foo.pl": Not an ARRAY reference at D.pm line 10.
这是原始文件。照原样,一切正常:
FormerC.pm
:
package FormerC;
use strict;
my %my_hash = ( key => 'value' );
my @my_array = qw( some strings inside array );
sub problematic_sub {
my ($hash_ref, $array_ref) = @_;
my @an_array = @$array_ref;
return \@an_array;
};
sub uses_problematic_sub {
problematic_sub(\%my_hash, \@my_array);
};
uses_problematic_sub();
1
这是两个新模块。有了这些,我得到了错误:
D.pm
:
package D;
use strict;
sub new { bless {}, shift };
sub problematic_sub {
my ($hash_ref, $array_ref) = @_;
my @an_array = @$array_ref;
return \@an_array;
};
1
C.pm
:
package C;
use strict;
use D;
my $d = D->new;
my %my_hash = ( key => 'value' );
my @my_array = qw( some strings inside array );
sub uses_problematic_sub {
$d->problematic_sub(\%my_hash, \@my_array);
};
uses_problematic_sub();
1