in reply to Binary conditionals

One character strings in Perl are still strings; not numbers as in C. So, $buffer == hex ('0x00') would match if, and only if, $buffer == 0, hence, if $buffer contains the character "0". And, as pointed out, when you write it, you write 0x17, aka 23, as digits.

Furthermore, hex('0x00') is redundant. It's equal to 0x00. The same with hex('0x17') which is the same as 0x17.

The right solution has already been mentioned; no need to repeat it.

Replies are listed 'Best First'.
Re^2: Binary conditionals
by moritz (Cardinal) on Sep 30, 2008 at 14:36 UTC
    C. So, $buffer == hex ('0x00') would match if, and only if, $buffer == 0, hence, if $buffer contains the character "0".

    Sorry, I have to disagree:

    $ perl -wle '"a" == 0 && print "yes"' Argument "a" isn't numeric in numeric eq (==) at -e line 1. yes

    So you see that 'a' == 0, and when you have warnings enabled, you also get a warning.

      Right. And this is why the OP complains that too many characters match (but not every character). $buffer==0x0 is true for every char except '1' to '9'.

      Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."