开发者

Perl method fails when I use a variable as opposed to a string literal

开发者 https://www.devze.com 2023-04-10 05:05 出处:网络
Getting some odd behaviour in a Perl script that I don\'t quite understand. I\'m trying to make some of my magic string literals into variables that can be modifie开发者_运维技巧d more easily.

Getting some odd behaviour in a Perl script that I don't quite understand. I'm trying to make some of my magic string literals into variables that can be modifie开发者_运维技巧d more easily.

I have an argument in my subprocedure called $in_feature. Right now it's value is simply "in_feature". I can print it out and it looks fine. So far so good...

This code fails, though:

if ($in_feature != "" && !$blockModel->is_field($in_feature))
{
    print "ERROR: was expecting to find a variable in the block model called $in_feature.\n";
        return;
}

If I remove the string comparison and change the method call back to the string literal it works as expected.

if (!$blockModel->is_field("in_feature"))
{
    print "ERROR: was expecting to find a variable in the block model called $in_feature.\n";
        return;
}

So the variable is somehow a string, that is equal to empty string, and can't be used in place of a string?!? Why's this?


String comparison in perl uses ne and eq instead of != and ==

Replace $in_feature != "" with $in_feature ne "" and it might fix your issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消