Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Wierd behaiviour of Filter::Util::Call

by ambrus (Abbot)
on Jan 29, 2008 at 18:14 UTC ( [id://664944]=perlquestion: print w/replies, xml ) Need Help??

ambrus has asked for the wisdom of the Perl Monks concerning the following question:

The following code is a simple hello world program preceded with a source filter that doesn't actually change the code in any way. This code works for me (in either perl 5.10.0 or 5.8.8 on x86-linux), that is, it prints hello world.

use Filter::Util::Call; BEGIN{ filter_add(sub{ my $s = filter_read; my $t = $_; $_ = $t; # <--- $s; }); } print "hello, world\n";

However, if I remove the line marked with the arrow, the resulting code,

use Filter::Util::Call; BEGIN{ filter_add(sub{ my $s = filter_read; my $t = $_; $s; }); } print "hello, world\n";

does not work anymore: specifically it does not print anything and exits with exit code 0.

I can't see why that statement makes a difference. Please explain.

Update 2008 jan 31: sent perl bug report.

Update 2008 feb 6: yes, sent it, but forgot to link to it. It's bug 50430.

Replies are listed 'Best First'.
Re: Wierd behaiviour of Filter::Util::Call
by BrowserUk (Patriarch) on Jan 29, 2008 at 21:08 UTC

    Some sort of deep doodoo in the XS voodoo. Perhaps the following code?

    # Call.XS ~line 130 SAVESPTR(DEFSV) ;/* save $_ */ /* make $_ use our buffer */ DEFSV = sv_2mortal(newSVpv("", 0)) ;

    A maybe workaround is to quote uses of $_, which seems to prevent the bug:

    use Filter::Util::Call; BEGIN{ filter_add(sub{ my $s = filter_read; my $t = "$_"; $s; }); } print "hello, world\n";

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://664944]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-24 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found