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

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.

  • Comment on Re^2: Very weird things when printing (may be an encoding issue?)

Replies are listed 'Best First'.
Re^3: Very weird things when printing (may be an encoding issue?)
by poj (Abbot) on May 30, 2013 at 11:40 UTC
    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.

Re^3: Very weird things when printing (may be an encoding issue?)
by Anonymous Monk on May 30, 2013 at 10:30 UTC

    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