in reply to Re: Format Streaming Text file with CR/LF
in thread Format Streaming Text file with CR/LF

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.
  • Comment on Re^2: Format Streaming Text file with CR/LF

Replies are listed 'Best First'.
Re^3: Format Streaming Text file with CR/LF
by ikegami (Patriarch) on Jul 22, 2008 at 19:24 UTC

    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.

Re^3: Format Streaming Text file with CR/LF
by BrowserUk (Patriarch) on Jul 22, 2008 at 19:24 UTC
      That will only add CRLF when run on Windows, but that might be ok or even desired.
        Thanks I'll give it a shot.