Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果条件不起作用,Perl哈希数据签入_Perl_If Statement_Hash - Fatal编程技术网

如果条件不起作用,Perl哈希数据签入

如果条件不起作用,Perl哈希数据签入,perl,if-statement,hash,Perl,If Statement,Hash,我是perl新手,正在研究使用哈希的perl代码。 我想知道为什么我不能在IF条件下使用散列数据。 比如说, $post_val{'module'}的值是扩展名 print "Module value: $post_val{'module'}\n"; if (chomp($post_val{'module'}) eq "extension") { print "correct...\n"; } else { print

我是perl新手,正在研究使用哈希的perl代码。 我想知道为什么我不能在IF条件下使用散列数据。 比如说,

$post_val{'module'}
的值是
扩展名

print "Module value: $post_val{'module'}\n";

if (chomp($post_val{'module'}) eq "extension") {
    print "correct...\n";
} else {
    print "wrong...\n";
}
我得到以下输出

模块值:扩展名

错了

这里出了什么问题?

返回删除的字符数,而不是
chomp
ed字符串

chomp($post_val{module})
if ($post_val{module} eq 'extension') {
  ...
返回删除的字符数,而不是
chomp
ed字符串

chomp($post_val{module})
if ($post_val{module} eq 'extension') {
  ...

chomp
返回删除的字符数,在本例中为
1

chomp $post_val{'module'};
if ($post_val{'module'} eq "extension") {
    print "correct...\n";
} else {
    print "wrong...\n";
}

chomp
返回删除的字符数,在本例中为
1

chomp $post_val{'module'};
if ($post_val{'module'} eq "extension") {
    print "correct...\n";
} else {
    print "wrong...\n";
}

谢谢,我被误解了chomp函数。谢谢,我被误解了chomp函数。