c****m 发帖数: 824 | 1 在call by reference函数里change hash,为什么出来就没有了?
#!/usr/bin/perl -w
use strict;
sub sethash
{
my (%hash) = %{$_[0]};
$hash{1} = 5;
print("$hash{1}\n");
}
my %mainhash = ();
&sethash(\%mainhash );
print("$mainhash{1}\n"); |
|
c****m 发帖数: 824 | 2 【 以下文字转载自 Linux 讨论区 】
发信人: ccccmm (猪喂曼玉), 信区: Linux
标 题: 这个perl的小程序为什么不work?
发信站: BBS 未名空间站 (Thu Mar 19 18:35:49 2009)
在call by reference函数里change hash,为什么出来就没有了?
#!/usr/bin/perl -w
use strict;
sub sethash
{
my (%hash) = %{$_[0]};
$hash{1} = 5;
print("$hash{1}\n");
}
my %mainhash = ();
&sethash(\%mainhash );
print("$mainhash{1}\n"); |
|
t*****g 发帖数: 1275 | 3 You did a hashtable copy.
#!/usr/bin/perl -w
use strict;
sub sethash
{
my $hash = shift;
$hash->{1} = 5;
print("$hash->{1}\n");
}
my %mainhash = ();
&sethash(\%mainhash );
print("$mainhash{1}\n");
|
|