in reply to Re^9: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
in thread Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)

I was replying to specifically to something dragonchild said. I hadn't read the thread that led up to his post until now.

"\0" produces a single character string consisting of character zero (NUL).
chr(0) produces a single character string consisting of character zero (NUL).
The problem is that you used '\0'.
'\0' produces a two character string consisting of a backslash (\) and a zero (0).

>perl -le "$s=qq{\0}; $,=q{, }; print length($s), qq{[$s]}, $s eq chr( +0) ?1:0" 1, [ ], 1 >perl -le "$s=q{\0}; $,=q{, }; print length($s), qq{[$s]}, $s eq chr(0 +) ?1:0" 2, [\0], 0

dragonchild should have recommended "\0" instead of the slower chr(0), but he was right to say '\0' is wrong.

And finally, I can accept that "null byte" (lowercase "null") can mean "a byte with value zero". When I corrected dragonchild, he had said NULL.

Replies are listed 'Best First'.
Re^11: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
by mr_mischief (Monsignor) on Sep 13, 2007 at 18:41 UTC
    Ah, that's correct. '\0' is wrong. "\0" it is then. I forgot for a moment that q() and '' don't interpolate even single character escapes.