小编hap*_*una的帖子

在perl中的子例程之后,哈希键值更改为数组引用

我在同一个哈希上创建子程序外部和内部的键.但是,在子例程之后,调用子例程之前创建的键中的值现在被解释为数组引用.

#!/usr/bin/perl
use module;
use strict;
use warnings;
my %hash;
my $count = 0;

my @array = ("a", "b", "c", "d");

for my $letter (@array) {
    $hash{$letter} = $count;
    $count++;
}

# need "\" to pass in hash otherwise changes
# will get lost outside of subroutine
foreach my $x (sort keys %hash) {
    print "first $hash{$x}\n";
}

module::add_ten(\%hash);

foreach my $p (sort keys %hash) {
    # $hash{$p} is printing array references, but before it was
    # printing the value …
Run Code Online (Sandbox Code Playgroud)

perl hash reference subroutine

0
推荐指数
1
解决办法
135
查看次数

标签 统计

hash ×1

perl ×1

reference ×1

subroutine ×1