[英]perl hash printing the value of a key
the below script stores the key value pairs.下面的脚本存储键值对。 Based on the input key given it should retrieve the corresponding value.根据给定的输入键,它应该检索相应的值。 In below code I am able to see the key value pairs from the first print but when I give one of the keys as an input, it throws an error saying "uninitialized hash".在下面的代码中,我能够从第一次打印中看到键值对,但是当我将其中一个键作为输入时,它会抛出一个错误,指出“未初始化的哈希”。 How to solve this ?如何解决这个问题?
...
for my $key ( sort keys %hash ) {
print "$key = $hash{$key}\n";
}
my $key = <STDIN>;
print "list is = $hash{$key}\n";
$key
contains the line entered including the trailing line feed . $key
包含输入的行,包括尾随换行。 Add添加
chomp($key);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.