in reply to Re: Break continuous lines of a text file based on character lengths
in thread Break continuous lines of a text file based on character lengths

If you set $\ to "\n", you don't even need the second statement — at least, not for every loop. Using the -l command line switch, you don't even need any code.
perl -pi.bak -e 'BEGIN{$/=\104;$\=qq/\n/}' filename.txt
or
perl -lpi.bak -e 'BEGIN{$/=\104}' filename.txt
For Windows, you'll have to adapt the quote characters around the code.

Replies are listed 'Best First'.
Re: Re(2): Break continuous lines of a text file based on character lengths
by davido (Cardinal) on Apr 20, 2004 at 16:02 UTC
    I wouldn't have immediately guessed that the -l switch would work because the POD for perlrun states that if a value is omitted from the -l switch, it sets $\ equal to $/. Since we're changing the value of $/ in the BEGIN{} block, and since the BEGIN{} block executes at least before the -p switch, I figured that using -l would set $\ to \104. Obviously that's not the case and I was just overthinking it.

    Good call bart. Great one-liner!


    Dave

Re: Re(2): Break continuous lines of a text file based on character lengths
by tariqahsan (Beadle) on Apr 20, 2004 at 15:40 UTC
    Thanks Bart! The one liner did work marvel for me.