Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Mixed Data

by krazken (Scribe)
on Nov 09, 2001 at 08:34 UTC ( [id://124292]=perlquestion: print w/replies, xml ) Need Help??

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,

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://124292]
Approved by root
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-05-28 17:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found