poage@sunny.ucdavis.edu (Tom Poage) (12/08/90)
Do you have a problem with the @* format construct? A format like
format STDOUT =
@*
$multiline_data
.
and the data being without a trailing newline, writes the data without
the trailing newline (what I might expect), but $= is decremented on
every write call as if the data *did* have a trailing newline. If the
data does have a trailing newline, $= is again decremented one-too-many
times.
Why? Has this been discussed/fixed, or am I using format+write wrong?
I've noticed this at patchlevels 37 and 41 on a Sun 3/150 (SunOS 4.0.3,
gcc 1.37.1).
Here's a test (indented for clarity):
#!/bin/perl
format STDOUT =
@*
$data
.
$data = "this\nis a multiline\ntest.";
$- = $=;
print '$data has ', $data =~ tr/\n/\n/, " lines\n";
print 'Before write $= is ', $=, "\n";
print 'Before write $- is ', $-, "\n";
write;
print 'After write $= is ', $=, "\n";
print 'After write $- is ', $-, "\n";
produces:
$data has 2 lines
Before write $= is 60
Before write $- is 60
this
is a multiline
test.After write $= is 60
After write $- is 57
Setting $data to "this\nis a multiline\ntest.\n" produces:
$data has 3 lines
Before write $= is 60
Before write $- is 60
this
is a multiline
test.After write $= is 60
After write $- is 56
A report I wrote had to have the number of calls to write added to $=
in order for the page length to be printed properly. :-\
Another thing, is it normal perlese to initialize $- (to $=) before
calling write the first time? For example, I had a report that set the
number of lines per page ($=) to 88. However, the first page had $=
set to 60 and subsequent pages had $= set to 88 (along with
corresponding $- values). One test I tried left $- at 99999996 ...
I found the source of that one in do_write().
Dazed, yet still amazed. Tom.
--
Tom Poage, Clinical Engineering
Universiy of California, Davis, Medical Center, Sacramento, CA
poage@sunny.ucdavis.edu {...,ucbvax,uunet}!ucdavis!sunny!poage