Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Very weird things when printing (may be an encoding issue?)

by bioinformatics (Friar)
on May 30, 2013 at 06:00 UTC ( [id://1035966]=note: print w/replies, xml ) Need Help??


in reply to Very weird things when printing (may be an encoding issue?)

So, you have output from a variant caller or database. Have you had to parse data from the bot previously, or is this a one-off file? Some ideas:

1) Check the API documentation to see if it gives any hints.
2) Check if the output file was made on a Mac. You can try setting $/ = "\12"; at the beginning of the script to test (it changes the delimiter from \n to \r).

Bioinformatics

Replies are listed 'Best First'.
Re^2: Very weird things when printing (may be an encoding issue?)
by dottornomade (Initiate) on May 30, 2013 at 10:21 UTC

    Thank you guys for the replies!

    Now I don't feel alone anymore.

    What I have to do is parse the file, retrieve the values and do some math.

    I opened the file with hex editor and found that odd lines end with "OA" (LineFeed), and even lines end with "OD" (CarriageReturn). And so here I am again, seeking for Perl wisdom at the monastery.

      In that case, use the CR to separate the records and the LF to split into lines;
      #!perl use strict; open IN,'<','weird.txt' or die "$!"; { local $/ = "\x0D"; while (<IN>){ my @lines = split /\x0A/; print $lines[0]."\n"; print $lines[1]."\n\n"; } }
      poj

        It works.

        Hail to the Perl Monks!

        Seriously, thank you.

      I opened the file with hex editor and found that odd lines end with "OA" (LineFeed), and even lines end with "OD" (CarriageReturn). And so here I am again, seeking for Perl wisdom at the monastery.

       perl -pi  -e " s/[\r\n]+/\n/g; " file
      dos2unix/Removing ^M char AKA dos2unix
      PerlIO::eol - PerlIO layer for normalizing line endings
      Text::FixEOL - Canonicalizes text to a specified EOL/EOF convention, repairing any 'mixed' usages
      File::LocalizeNewlines - Localize the newlines for one or more files

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1035966]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-23 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found