question on Perl# Unix - 噫吁兮,危乎高哉
k*e
1 楼
参考书"Programming Perl" 有这样一段程序,参2.7.2节 "Passing References",哪位
大侠能解释一下那个“return”语句。实在是有些糊涂,总觉得“$seen{$_} == @_”永
远是FALSE,这样, inter能返回有效的list么?
@common = inter( \%foo, \%bar, \%joe );
sub inter {
my ($k, $href, %seen); # locals
foreach $href (@_) {
while ( ($k) = each %$href ) {
$seen{$k}++;
}
}
return grep { $seen{$_} == @_ } keys %seen;
}
大侠能解释一下那个“return”语句。实在是有些糊涂,总觉得“$seen{$_} == @_”永
远是FALSE,这样, inter能返回有效的list么?
@common = inter( \%foo, \%bar, \%joe );
sub inter {
my ($k, $href, %seen); # locals
foreach $href (@_) {
while ( ($k) = each %$href ) {
$seen{$k}++;
}
}
return grep { $seen{$_} == @_ } keys %seen;
}