develooper Front page | perl.perl5.porters | Postings from October 2013

Re: deprecate say!

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
October 5, 2013 20:04
Subject:
Re: deprecate say!
Message ID:
CAD2L-T0DFofHxqtyaTNjvHpaSP78z+Pm=aE5WnwrTvXKTn4xxg@mail.gmail.com
On Sat, Oct 5, 2013 at 2:45 PM, Ricardo Signes
<perl.p5p@rjbs.manxome.org> wrote:
> No, not really.
>
> I started using say in the days of 5.9, and it was great.
>
> Then I hit bugs when say-ing to a tied filehandle.  Others did, too, this was
> https://rt.perl.org/rt3/Ticket/Display.html?id=49264
>
> This was fixed by making `say $tied_fh $str` equivalent to:
>
>   $\ = "\n"; say $tied_fh $str;
>
> Now there were two bugs:
>
> 1. Most people hadn't accounted for $\ in their &PRINT implementations.
>    That was their bug, tough!
>
> 2. The assignment to $\ wasn't localized!
>    That was our bug.  https://rt.perl.org/rt3/Ticket/Display.html?id=119927
>
> In 5.18.0, `say $tied_fh $str` became equivalent to:
>
>   { local $\ = "\n"; say $tied_fh $str; }
>
> This helped, too, but now there's a bug still left.  Here's a contrived
> (and not tested) tied handle class:
>
>   package Tied_Handle;
>   package Event::Logger 'log_method_call';
>   ...
>   sub PRINT {
>     my ($self, @args) = @_;
>
>     log_method_call($self, PRINT => @args);
>     print @args;
>     return 1;
>   }
>
> and:
>
>   package Event::Logger;
>   sub log_method_call {
>     print "$_[1] called on $_[0]: @_[ 2 .. $#_ ]\n"
>   }
>
> The print in Event::Logger becomes a `say` because $\'s localized setting for
> the benefit of Tied_Handle::PRINT is still in effect.
>
> PRINT can't fix that because it can't tell whether $\ is set because `say`
> happened or because $\ had been globally set.  I don't see a simple real fix.
> Do you?
>
> A lousy fix may be to add SAY to the tied handle interface and use that when
> available.
>
> --
> rjbs

Why isn't `say FILEHANDLE LIST` the same as
`print FILEHANDLE LIST, "\n"` ?

or

`print FILEHANDLE LIST, ($\ // "\n")`

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About