[求助]数组在传递给子函数后怎么会被清空了??

[求助]数组在传递给子函数后怎么会被清空了??

[求助]数组在传递给子函数后怎么会被清空了??
if (time - $last_scan_time > $scan_inter * 30) {
$last_scan_time = time;
foreach (@hospitals){
do_scan($_);
print $_;
}
}
$_在do_scan($_);之后就不能print了,变成未定义
@hospitals在foreach之后就为空了
[color=red]
我把下面红色的部分注释掉后,就正确了,不知到为什么,这个<FILE1>句柄和参数有什么关系
[/color]
请高手指点


sub do_scan{
my $hospital = shift;

my @new_mml = sort (grep { /_$hospital\.mml$/}(glob "$dir*.mml"));

my $md5; #md5-digest object claimed here
my $sha1; #SHA1-digest object claimed here


while (my $one = shift @new_mml){
open (FILE1,"<$one") or die "Can't open '$one': $!";
binmode (FILE1);

$md5 = Digest::MD5 -> new;
$sha1 = Digest::SHA1 -> new;

defined($digest1{$hospital} -> [0]) and $md5 -> add($digest1{$hospital} -> [0]);
defined($digest2{$hospital} -> [0]) and $sha1 -> add($digest2{$hospital} -> [0]);


[color=red] while (<FILE1>){
$md5 -> add($_);
$sha1 -> add($_);
}[/color]

close (FILE1);

my $basename = basename $one;
$md5 -> add($basename); #bind file name in the digest
$sha1 -> add($basename);


if (-e $hashed_mml.$basename){warn "file '",$basename,"' already exists!\n";next;}
system "mv $one $hashed_mml"; #use shell to move digested mml files to a new directory

my $basename1 = $mml_md5{$hospital}.$basename.".md5";
my $basename2 = $mml_sha1{$hospital}.$basename.".sha1";

if (-e $basename1){warn "'$basename1' already exisits!\n";next;}
open (FILE2,">$basename1") or die "Can't creat '$basename1': $!";
if (-e $basename2){warn "'$basename2' already exisits!\n";next;}
open (FILE3,">$basename2") or die "Can't creat '$basename2': $!";

my $temp_md5 = $md5 -> hexdigest;
my $temp_sha1 = $sha1 -> hexdigest;
print FILE2 $temp_md5;
print FILE3 $temp_sha1;

close (FILE2);
close (FILE3);


unshift @{$digest1{$hospital}},$temp_md5;
unshift @{$digest2{$hospital}},$temp_sha1;


unshift @{$md5names{$hospital}},$basename1;
unshift @{$sha1names{$hospital}},$basename2;


if(@{$digest2{$hospital}} >= $group_amount){
my $temp_c = sprintf '%04u', $count{$hospital}++;
@{$digest1{$hospital}} = @{$digest2{$hospital}} = ();
@{$md5names{$hospital}} = @{$sha1names{$hospital}} = ();

my $oldname1 = $basename1;
$basename1 =~ s/\.md5$/_$temp_c\.md5/;
system "mv $oldname1 $basename1";

my $oldname2 = $basename2;
$basename2 =~ s/\.sha1$/_$temp_c\.sha1/;
system "mv $oldname2 $basename2";

}

}

}
[/color][/color][/color][color=#FF6600][color=red][color=red][color=red][color=red]




   

我把上面红色的部分注释掉.




   

因为$_是Perl的特殊变量,.
因为$_是Perl的特殊变量,因为在do_scan的函数中用到了$_,所以在foreach循环中$_的值就丢失了
谢谢--这个小问题害我找.
谢谢
这个小问题害我找好久
原来以为在进入一个新的循环时,原来的$_会被保存起来,弄错了