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

hello monks

my script runs on win32 to process formatted text files that came originally from the mac

before trying to edit them i used the following snipppet to change the default record separator to \r and look at what i got

{ local $/; $/="\r"; open INFILE, $ARGV[0]; open OUTFILE, ">$ARGV[1]"; while(<INFILE>){ chomp; print OUTFILE "$_\n"; } }
sorts out the line endings fine but my output has lots of strange squares in it

Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: text files from mac
by polettix (Vicar) on Apr 13, 2005 at 12:00 UTC
    Line ending in Win32 is "\r\n", so you probably shouldn't strip the "\r" chomping the input line, as per sh1tn suggestion or, golfing a bit:
    open INFILE, $ARGV[0] or die $!; open OUTFILE, $ARGV[1] or die $!; local $\ = "\n"; # Appended to any print invocation print OUTFILE while(<INFILE>);

    Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

    Don't fool yourself.
Re: text files from mac
by sh1tn (Priest) on Apr 13, 2005 at 10:52 UTC
    open INFILE, $ARGV[0] or die $!; open OUTFILE, $ARGV[1] or die $!; while(<INFILE>){ s/$/\n/; print OUTFILE $_; }


Re: text files from mac
by ryantate (Friar) on Apr 13, 2005 at 20:25 UTC
    Your script looks like it would work fine if it were fed pure Mac OS 9 or earlier text. Probably what's happening is you are dealing with text from Mac OS X, which has unix-style newlines, with \015 (\f) as the newline (not \r, which is \012, and was the traditional Mac newline before OS X). This will result in a square when reading on a Windows machine because it does not recognize \015 as a newline at all.

    The actual newlines in your output come not from the original file but from your printing "\n" in the while loop, since \n is the "logical newline" for your system, in your case Windows, and thus generates the correct \012\015 sequence.

    PS If I am correct about your using Mac OS X files then simply changing $/ to "\015" (untested and not sure if I have the syntax right) should solve your problem.

      ta! the first too snippets give the same output as my code prompting me to think that there is some other problem like corrupted disk/data the machine isn't OS X though was the first thing i checked coz its the only kind of mac i know anything about (and then the only thing i no is that its basically UNIX) i was hoping to ftp the beasts to my LINUX machine and then no problem but alas this wasn't the case