At 9:04 PM -0500 11/19/01, Michael G Schwern wrote:
>On Mon, Nov 19, 2001 at 07:15:26PM -0600, Craig A. Berry wrote:
>> At 6:57 PM -0500 11/19/01, Michael G Schwern wrote:
>> > Something in vmsperl has decided that you always
>> >need a newline at the end of a print.
>> >
>> >$ perl -e "print 'foo'"
>> >foo
>> >$
>>
>> As Peter said, it's probably in the terminal driver (or the mailbox
>> driver in the case of a pipe). I tried modifying runperl like so:
>>
>> --- t/test.pl;-0 Thu Nov 15 19:10:54 2001
>> +++ t/test.pl Sat Nov 17 15:47:18 2001
>> @@ -249,6 +249,7 @@
>> }
>> my $result = `$runperl`;
>> $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
>> + $result =~ s/\n$// if $is_vms; # backquotes always give you \n at the end
>> return $result;
>> }
>
>That's no good, what if you *did* want the newline on the end?
Too true, which is one reason (aside from not stopping all the
failures) that I didn't submit it.
>The problem is there's no way to distinguish between the output of
>
> perl -e "print 'foo'"
>
>and
>
> perl -e "print qq{foo\n}"
And I believe this is by design. The device drivers are helping you
out here so you never have a bunch of confusing garbage left over
from your last command.
>Even if we tried something like:
>
> $ perl -e "print 'foo'" > foo.tmp
> $ pipe cat foo.tmp | perl -e "print length <STDIN>"
>
>still no good. Even though there's no newline in foo.tmp
>
> $ wc foo.tmp
> 0 1 3 foo.tmp
>
>the pipe still puts that damned extra newline on the end.
>
> $ pipe cat foo.tmp | wc
> 1 1 4
Note that the pipe command from the shell does not use the same
beasties as Perl's pipes. The shell pipe uses a special device
driver developed by the maintainers of the shell and they have not
chosen to implement it in sufficiently general a fashion that it
could be used by the C library to implement popen() and such. The C
library uses a virtual device called a mailbox instead. In broad
brushstrokes, Perl uses the same basic approach as the C library but
has its own implementation to get around a number of problems.
That's a long-winded way of saying that testing with the pipe command
won't tell you what Perl will do.
>Ok... so this looks like it's a terminal thing (seeing as how
>redirecting the output to a file didn't produce a trailing newline).
>Can't system() and `` just be told not to do it, since there's no
>terminal involved?
There's no terminal, but there's a mailbox. I have a feeling it will
do the same thing a terminal will do, but I don't know for sure.
Chuck, do you?
--
____________________________________________
Craig A. Berry
mailto:[EMAIL PROTECTED]
"Literary critics usually know what they're
talking about. Even if they're wrong."
-- Perl creator Larry Wall