perl hash值如何查询 求排错
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/08/19 03:40:36
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);
![perl hash值如何查询 求排错](/uploads/image/z/17044780-4-0.jpg?t=perl+hash%E5%80%BC%E5%A6%82%E4%BD%95%E6%9F%A5%E8%AF%A2+%E6%B1%82%E6%8E%92%E9%94%99)
print "$a{$tmp}";
改成
print "@{$a{$tmp}}";
再问: 我知道了,这个my $tmp = @_;列表上下文,给的是@_元素的个数,而不是第一个值,用shift取出来就行。
改成
print "@{$a{$tmp}}";
再问: 我知道了,这个my $tmp = @_;列表上下文,给的是@_元素的个数,而不是第一个值,用shift取出来就行。