Perl: Removing NULL characters (0x00)
peter at bowenfamily.org
Fri Mar 4 17:36:50 MST 2005
I suggested it because this is what pack/unpack was designed to do...
extract data from streams. In this case a null terminated string.
I've seen code where this is done with substrs to try to chop off the
junk at the beginning and lop off the terminator at the end - because
the programmer didn't realize that the "junk" was a couple of ints to
describe the type of message, and the length of the text, and the null
was the string terminator. The worst was when I wrote the driver for
the XM PCR... the existing stuff was trying to guess wheree the data was
and how many messages to expect. By unpacking and handling the data, we
converted it to an event driven model that can Tivo radio in perl... it
was pretty cool - it still is :)
Alan Young wrote:
>> What you're really looking for is pack/unpack try this...
>>unpack("A*",$value) - it's pretty common for c++ stuff to marshall a
>>struct together and send it to you, and perl just sees a really long string.
>Just to get rid of nulls? or do you have another reason for suggesting pack?
More information about the PLUG