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

deprecate say!

Thread Next
Ricardo Signes
October 5, 2013 19:46
deprecate say!
Message ID:
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

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.

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;


  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


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About