I am parsing an XML file, and after extracting some information, I want to see if a particular field has a '/' (slash) in it. So I do the following code:
if (defined($orgUIDLookup{$orgUidMid}))
{
my $country = $orgUIDLookup{$orgUidMid};
print "country = $country ";
if ($country !~ ?/?)
{
print "OK\n";
$airportRef{country} = $country;
}
else
{
print "no good\n";
$needHelp = 1;
}
}
But I seem to be getting inconsistent results for the nodes with a slash in them:
grep '^country = .*/' foo
country = CN/MA/RE no good
country = CN/MA/RE OK
country = CN/MA/RE OK
country = CN/MA/RE OK
country = RB/MJ OK
country = RB/MJ OK
country = RB/MJ OK
country = CN/MA/RE OK
country = CN/MA/RE OK
country = RB/MJ OK
country = RB/MJ OK
country = CN/MA/RE OK
country = CN/MA/RE OK
country = RB/MJ OK
country = RB/MJ OK
country = KR/TV OK
country = KR/TV OK
country = KR/TV OK
country = WS/AQ OK
country = AA/NT OK
country = AA/NT OK
country = AA/NT OK
country = AA/NT OK
country = AA/NT OK
country = AA/NT OK
Why would this test would go through the else
branch ok the first time, but go through the if
branch every other time?