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

deprecate say!

Thread Next
From:
Ricardo Signes
Date:
October 5, 2013 19:46
Subject:
deprecate say!
Message ID:
20131005194553.GA20130@cancer.codesimply.com
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

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