We don't bite newbies here... much | |
PerlMonks |
Re^7: How to find Unicode: 0x13 in Fileby AnomalousMonk (Archbishop) |
on Nov 19, 2016 at 17:27 UTC ( [id://1176160]=note: print w/replies, xml ) | Need Help?? |
... I have no idea why it does that. ... splitting the two bytes into individual bytes. Is this behavior of unpack documented?
The h (un)pack template specifier is (and always has been, as far as I can recall) documented to unpack: This means that a string containing an ASCII '1' character (a byte with the hex value 0x31 — this is also a UTF8 representation of '1') will unpack as '13' with h and you have your false positive. (It also means that h unpacks an actual 0x13 character as '31' and you have a false negative!) I wouldn't do it this way, but if you absolutely have to use a regex to search a hex-unpacked string for the hex representation of the character 0x13, I would first make sure the nybble order of the unpack template specifier I'm using is consistent with the unpacked character pair I'm looking for (e.g., 'H' with '13') and then make sure the regex only matches on even character offset boundaries: (Runs the same on ActiveState 5.8.9 and Strawberry 5.14.4.1.) Personally, I've always found the behavior of the H and h (un)pack specifiers counterintuitive and tricksey. Whenever I use them, I always have go to the pack and perlpacktut documentation and tutorial and stare at the info therein for a while before I can get it right. Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|