perl hash值如何查询 求排错
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/06 04:23:49
perl hash值如何查询 求排错
use warnings;
use strict;
my %a = (
1 => [1,2,3,4],
2 => [2,3,4,5],
3 => [3,4,5,6],
4 => [4,3,2,1],
5 => [5,4,3,2],
6 => [6,5,4,3]
);
sub search {
my $tmp = @_;
if (exists($a{$tmp})) {
print "$a{$tmp}";
print "\n";
} else {
print " \n";
}
}
chomp (my $in = );
search($in);
use warnings;
use strict;
my %a = (
1 => [1,2,3,4],
2 => [2,3,4,5],
3 => [3,4,5,6],
4 => [4,3,2,1],
5 => [5,4,3,2],
6 => [6,5,4,3]
);
sub search {
my $tmp = @_;
if (exists($a{$tmp})) {
print "$a{$tmp}";
print "\n";
} else {
print " \n";
}
}
chomp (my $in = );
search($in);
print "$a{$tmp}";
改成
print "@{$a{$tmp}}";
再问: 我知道了,这个my $tmp = @_;列表上下文,给的是@_元素的个数,而不是第一个值,用shift取出来就行。
改成
print "@{$a{$tmp}}";
再问: 我知道了,这个my $tmp = @_;列表上下文,给的是@_元素的个数,而不是第一个值,用shift取出来就行。