Re: Zero equals pipe??
- From: "Jürgen Exner" <jurgenex@xxxxxxxxxxx>
- Date: Sun, 24 Sep 2006 03:12:22 GMT
ilya2@xxxxxxx wrote:
My perl program had some conditional statements that checked whether a
given characters was a pipe "|" or not. The program behaved strangely,
and I quickly realized it was treating pipes and zeros equivalently.
To make sure I was not going insane, I put the following checks:
if ( '1' == '|') { ... some statement ... }
if ( '0' == '|') { ... another statement ... }
By any sensible measure, both statements must return FALSE. First one
did that. Second one returned TRUE.
What's going on and how do I get around it?
Well, the numerical values of your three strings are
'1' ==> 1
'0' ==> 0
'|' ==> 0
In other words you got the following comparions (partially evaluated):
if ( 1 == 0 ) { ... some statement ... }
if ( 0 == 0 ) { ... another statement ... }
If you had used warnings then perl would have told you.
You may also want to check the FAQ
"What's wrong with always quoting "$vars"?"
There is absolutely no need to quote your numbers and in fact those
superflous quotes led you down the wrong path.
jue
.
- References:
- Zero equals pipe??
- From: ilya2
- Zero equals pipe??
- Prev by Date: Re: Zero equals pipe??
- Next by Date: FAQ 8.38 How do I timeout a slow event?
- Previous by thread: Re: Zero equals pipe??
- Next by thread: FYI: Something I saw on generating random-numbers
- Index(es):
Relevant Pages
|