krazken has asked for the wisdom of the Perl Monks concerning the following question:

I am dealing with straight file read it in/write it out type of stuff, but I have Binary zeros (Nulls) whatever you want to call them inside my data. I need to get rid of it. I have tried
s/\x00//g s/\0//g s/\000//g
I have thought about using tr, but I have never had much luck with it. thanks krazken

Replies are listed 'Best First'.
Re: Mixed Data
by cmilfo (Hermit) on Nov 09, 2001 at 09:37 UTC
    If all you have is ASCII data with binary zeros, you might try just stripping out anything that isn't printable ASCII. Something like this might work.
    while($line = <INFILE>) { $line =~ s{[^ -~]}{}g; # [^ -~] matches non printable ASCII chars print "$line\n"; # your new lines are gone after the above }

    Just a thought...
      Someone else suggested...
      while (<>) { print join ' ',split /\x00/; }
      And this does remove the binary zeros from inside of the records.
        Someone else suggested...

        That was me, but you've added a space to the join. If you want to substitute space for null, tr/\000/ /; should work (tr/// wants octal).

        In any case, there is no reason s/\x00//g; wouldn't work if split on that regex does. How about posting some more of your code so we can see what the problem really is?

        After Compline,
        Zaxo

Re: Mixed Data
by jeroenes (Priest) on Nov 09, 2001 at 12:52 UTC