IF 条件下的 Perl 哈希数据检查不起作用
Perl hash data check in IF condition not working
我是 perl 新手,正在研究使用散列的 perl 代码。
我想知道为什么我不能在 IF 条件下使用哈希数据。
例如,
$post_val{'module'}
的值为 extension
。
print "Module value: $post_val{'module'}\n";
if (chomp($post_val{'module'}) eq "extension") {
print "correct...\n";
} else {
print "wrong...\n";
}
我得到以下输出,
Module value: extension
wrong...
这里出了什么问题?
chomp
returns 删除的字符数,而不是 chomp
ed 字符串。
chomp($post_val{module})
if ($post_val{module} eq 'extension') {
...
chomp
returns 删除的字符数,在本例中为 1
.
chomp $post_val{'module'};
if ($post_val{'module'} eq "extension") {
print "correct...\n";
} else {
print "wrong...\n";
}
我是 perl 新手,正在研究使用散列的 perl 代码。 我想知道为什么我不能在 IF 条件下使用哈希数据。 例如,
$post_val{'module'}
的值为 extension
。
print "Module value: $post_val{'module'}\n";
if (chomp($post_val{'module'}) eq "extension") {
print "correct...\n";
} else {
print "wrong...\n";
}
我得到以下输出,
Module value: extension
wrong...
这里出了什么问题?
chomp
returns 删除的字符数,而不是 chomp
ed 字符串。
chomp($post_val{module})
if ($post_val{module} eq 'extension') {
...
chomp
returns 删除的字符数,在本例中为 1
.
chomp $post_val{'module'};
if ($post_val{'module'} eq "extension") {
print "correct...\n";
} else {
print "wrong...\n";
}