in reply to how do I line-wrap while copying a file to stdout?

chomp; print join("\n", grep(/./, split(/(.{80})/))), "\n";
The chomp is to get rid of the newline, since we don't really want to count it as a character (i.e. 80 chars + a newline should go on one line even though it's more than 80 chars).

Replies are listed 'Best First'.
Re: Re: how do I line-wrap while copying a file to stdout?
by chipmunk (Parson) on Apr 20, 2001 at 21:06 UTC
    How about: print "$_\n" for /.{1,80}/g;
Re: Re: how do I line-wrap while copying a file to stdout?
by ams (Initiate) on Apr 20, 2001 at 11:24 UTC
    this seems to drop (not print) the first 80 characters of the very long lines. -allan
Re: Re: how do I line-wrap while copying a file to stdout?
by bpaulsen (Initiate) on Apr 20, 2001 at 19:28 UTC
    I think you had it except for the grep command. I'm not sure what that's there for. I have:
    chomp $string; print join( "\n", split( /(.{80})/, $string ) ), "\n";
      Sorry. For a drop in replacement, you can use:
      chomp; print join( "\n", split( /(.{80})/ ) ), "\n";