in reply to Format Streaming Text file with CR/LF

If I understand correctly, you are trying to read in a file where the record (line) seperator is CRLF. So why don't you set the input record seperator to CRLF?
# Any system binmode $fh; local $/ = "\x0D\x0A"; while (<$fh>) { chomp; ... }

Note that Perl on Windows system covertly converts CRLF to LF on input, so you don't have to do anything.

# Windows only while (<$fh>) { chomp; ... }

Replies are listed 'Best First'.
Re^2: Format Streaming Text file with CR/LF
by drodinthe559 (Monk) on Jul 22, 2008 at 19:13 UTC
    I'm trying to add the CR/LF in a line feed text file. The text file when I get it is on long line with no CR/LF in it.I want to create a new line at every 90th character.

      In that case, I pretty much answered this question yesterday.

      From a file handle:

      binmode $fh_in; binmode $fh_out; local $/ = \90; while (<$fh_in>) { print $fh_out "$_\x0D\x0A"; }

      From a string:

      binmode $fh_out; while (length($str)) { my $rec = substr($str, 0, 90, ''); print $fh_out "$rec\x0D\x0A"; }

      If you want CRLF when run on Windows and LF when run on other OSes, get rid of the binmode and replace \x0D\x0A with \n.

        That will only add CRLF when run on Windows, but that might be ok or even desired.