in reply to Re: 80 characters long
in thread 80 characters long
$/ doesn't help. (And don't forget the RHS needs to be a reference: local $/ = \80;)
local $/ = \10; # Easier to visualize than 80. print "$_\n" while <DATA>; __DATA__ abcdefghijklm ABCDEFGHIJKLM
outputs
abcdefghij klm ABCDEF GHIJKLM
instead of
abcdefghij klm ABCDEFGHIJ KLM
read (or unbuffered sysread) can do it with some coaxing.
my $wrap_len = 10; my $buf = ''; LOOP: for (;;) { while (length($buf) < $wrap_len+1) { my $rv = read(DATA, $buf, $wrap_len+1-length($buf), length($buf) +); die if not defined $rv; last LOOP if not $rv; } ($buf =~ s/^(.*)\n// || $buf =~ s/^(.{0,$wrap_len})//) and print("$1\n"); } print($buf); __DATA__ abcdefghijklm ABCDEFGHIJKLM
The +1 avoids adding a \n before another \n.
|
|---|