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.
精彩评论