$/ 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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.