Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

According to say, say is shorthand for { local $\ = "\n"; print LIST }. Consistent with that perltie says that the PRINT method of a tied handle gets called for both print $some_tied_handle and say $some_tied_handle:

PRINT this, LIST
This method will be triggered every time the tied handle is printed to with the print() or say() functions...

However, it seems that when a handle is tied, PRINT is called but local $\="\n" isn't done beforehand. Instead, whatever value of $\ was available before the call to say is used and never overridden. Here is some sample code that demonstrates the issue:

{ package Foo; sub TIEHANDLE { my ($sClass, $fh) = @_; return bless([$fh], $sClass); } sub PRINT { my $self = shift; my $fh = $self->[0]; CORE::print $fh "tied to $self:", @_; } } my $x=gensym; tie *$x, 'Foo', \*STDOUT; local $\="\n***\n"; say "Not tied: I'm just saying ..."; say $x "I'm just saying ..."; # outputs (note that say $x is followed by "\n***\n" # not "\n" # # Not tied: I'm just saying ... # tied to Foo=ARRAY(0x8197ed0):I'm just saying ... # ***

Am I doing something wrong? Is there some trick to making say $some_tied_handle ... act like say STDOUT ...? Or is this a bug? If it is a well known a bug, I didn't have much luck finding it using a general google search. Is there a better way to check to see if a bug is a known perl bug?

Platform is Debian (Lenny) perl=5.10.0

Update: Replaced broken shortcut with explict http link, in light of toolic's reply below.


In reply to Why won't say act like say when its tied? by ELISHEVA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found