### When is 03 not equal to 03?

by spacewarp (Pilgrim)
 on Oct 14, 2001 at 00:30 UTC Need Help??
spacewarp has asked for the wisdom of the Perl Monks concerning the following question:

In the following code, \$this_category is a two-digit value that's read from a local file. \$tt is a variable I defined for debugging purposes.
```\$tt = "03";
if (\$tt == \$this_category) { print "YES"; }
else {print "NO: tt--\$tt-- this_category--\$this_category--";}
The response that the web browser gets is:
```NO: tt--03-- this_category--03--
I am running perl 5.005_03 and using taint checking and -w. Does anyone have any idea what's happening here? I need the \$this_category value to work for a hash lookup.

Spacewarp

DISCLAIMER:
Use of this advanced computing technology does not imply an endorsement
of Western industrial civilization.

Replies are listed 'Best First'.
Re: When is 03 not equal to 03?
by chipmunk (Parson) on Oct 14, 2001 at 02:01 UTC
Since the issue hsa already been resolved, here's a related, mildly interesting tidbit. 03 should always be equal to 03, but... when is 033 not equal to 033?

```\$var = '033';
if (\$var == 033) {
print "Equal.\n";
} else {
print "Not equal.\n";
}
As perldata explains, octal and hexadecimal numbers in strings are not automatically converted to their decimal equivalents, so '033' becomes 33, while the numeric literal 033 becomes 27.
Re: When is 03 not equal to 03?
by George_Sherston (Vicar) on Oct 14, 2001 at 01:01 UTC
It's not much consolation, but it should work. Perl should be forcing your variables into numerical context if necessary, so that the comparison shd be ok with either == or eq. I'd be interested to see how \$this_category is defined, but I've tried defining it all different ways and I can only get your error message by defining it as "04"!

I'm using ActivePerl 5.6.1.629, however, which may make the difference.

§ George Sherston
Re: When is 03 not equal to 03?
by spacewarp (Pilgrim) on Oct 14, 2001 at 00:33 UTC
PS.. I've tried the if comparison with both == and eq, and if fails both ways.

Spacewarp

DISCLAIMER:
Use of this advanced computing technology does not imply an endorsement
of Western industrial civilization.
Once again, my faith in Murphy is confirmed. I figured it out soon after I posted the question. \$this_category was being changed in a way that didn't show up in the web browser, ie 03 . Sorry for the wasted node.

On second thought, let this be a lesson to others: When debugging with the web browser, always check the HTML source code.

Spacewarp

DISCLAIMER:
Use of this advanced computing technology does not imply an endorsement
of Western industrial civilization.

Create A New User
Node Status?
node history
Node Type: perlquestion [id://118684]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2018-03-17 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (223 votes). Check out past polls.

Notices?