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

Re: deprecate say!

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
October 5, 2013 20:33
Subject:
Re: deprecate say!
Message ID:
20131005203316.15814.qmail@lists-nntp.develooper.com
Ricardo Signes wrote:
> In 5.18.0, `say $tied_fh $str` became equivalent to:
> 
>   { local $\ =3D "\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) =3D @_;
> 
>     log_method_call($self, PRINT =3D> @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 f=
> or
> 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 fi=
> x.
> Do you?

Event::Logger needs to localise $\ before printing, as has always been
the case whenever $\ is set by the main script.  Nothing new here.


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