小编eni*_*osp的帖子

无法将哈希作为模块中的引用传递

我想将哈希引用传递给模块.但是,在模块中,我无法获得哈希值.

这个例子:

#!/usr/bin/perl
#code.pl
use strict;
use Module1;

my $obj = new Module1;

my %h = (
    k1 => 'V1'
);

print "reference on the caller", \%h, "\n";

my $y = $obj->printhash(\%h);
Run Code Online (Sandbox Code Playgroud)

现在,Module1.pm:

package Module1;
use strict;
use Exporter qw(import);
our @EXPORT_OK = qw();
use Data::Dumper;

sub new {
    my $class = $_[0];
    my $objref = {};
    bless $objref, $class;
    return $objref;
}


sub printhash {
    my $h = shift;

    print "reference on module -> $h \n";
    print "h on …
Run Code Online (Sandbox Code Playgroud)

perl hash

4
推荐指数
2
解决办法
99
查看次数

标签 统计

hash ×1

perl ×1