in reply to Null \x00 being replaced by space \x20

Hello BaldGorilla, and welcome to the Monastery!

I assume the line print $new_gpd_fh "$line"; is meant to be print $new_fh "$line";? With this change made, I cannot reproduce your problem.

Specifically, I created a text file, then used a hex editor to insert a null (\x00) at a suitable place in the text, and ran the script. The resulting new file has a null character in the correct place, as expected. (Confirmed both in the hex editor and in Notepad++, which displays a NUL control character.)

Are you sure that your new file contains a space character in place of the null? Or could the space you are seeing be an artefact of the way you are viewing the file contents?

Cheers,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Null \x00 being replaced by space \x20
by BaldGorilla (Initiate) on Nov 10, 2018 at 04:18 UTC
    Yes, fixed the the typo, sorry about that. I'm using UltraEdit and Notepad++ and I see the null and space difference. Is there any way to send screen shots?
      Is there any way to send screen shots?

      Better just to get perl to tell you what's in the file.
      As Athanasius suggested, I suspect that the file really does contain a NULL, and the tool you're using to look at it converts it to a space.

      On Windows 7 (perl-5.28.0), I created a file (null.txt) by running:
      C:\_32> perl -e "$s = 'x' . chr(0) . 'y';print $s;" >null.txt
      I then examined the contents of null.txt by running:
      C:\_32> perl -le "open RD, '<', 'null.txt'; $x = <RD>; chomp $x; print + ord substr($x, 0, 1); print ord substr($x, 1, 1);print ord substr($x +, 2, 1); print length $x;" 120 0 121 3
      After using your script to create null.txt.new, I then ran the same one liner to ascertain the contents of null.new.txt
      C:\_32> perl -le "open RD, '<', 'null.txt.new'; $x = <RD>; chomp $x; p +rint ord substr($x, 0, 1); print ord substr($x, 1, 1);print ord subst +r($x, 2, 1); print length $x;" 120 0 121 3
      So it looks to me that I also am unable to reproduce the problem.

      Cheers,
      Rob
        It was an issue with the text editor converting it to a space. Thank you all for the assistance!