这是我的代码 -
print $cpu_arch."\n";
if ($cpu_arch eq'AMD64') {
print "Remote machine is 64bit\n";
}
根据CPU架构,$ cpu_arch返回x86或AMD64。 问题是无论$ cpu_arch返回什么,if循环条件都不会得到满足。我试过chomp'ing $ cpu_arch,但这似乎也没有帮助。
答案 0 :(得分:4)
字符串的运算符为eq
。您的问题不在您的运营商中,而是在数据中。您可能不正确地缓冲(更改$|
变量)或$cpu_arch
具有尾随空格。或者也许你正在寻找正则表达式匹配而不是文字匹配(那么你想要/AMD64/
)
答案 1 :(得分:1)
您的代码是正确的。 $cpu_arch
不包含AMD64
,或者您错误地认为if
条件为假(可能是因为缓冲)。
以下内容可帮助您检查$cpu_arch
。
use Data::Dumper;
{
local $Data::Dumper::Useqq = 1;
print(Dumper($cpu_arch));
}