为什么我的Perl脚本不能区分"0"和"""`?

ric*_*uck 2 perl replace substr

Perl noob在这里 - 我有以下脚本

if(substr($pc, 3,1)!=" "){
       $newpc = substr($pc, 0, 4) . " " . substr($pc, 4);
}
Run Code Online (Sandbox Code Playgroud)

它被设计为在邮政编码中放置一个空格,例如NN141NJ变成NN14 1NJ......但是对于NN102DE它没有做任何事情的邮政编码,Perl是否识别" "并且"0"同样如此?0作为第四个字母,我怎样才能使用perl而不是忽略字符串?

e.d*_*dan 7

ne而不是!=.后者用于数字比较,两者都0在你的情况下.看到perldoc perlop