Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Filter::Util::Call does not work in eval?

by withering (Monk)
on Sep 25, 2014 at 07:33 UTC ( [id://1101913]=perlquestion: print w/replies, xml ) Need Help??

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

Hello fellow monks.

The code below uses a source code filter, which replaces all "word"s with "worlds". However, it only prints "Hello word" instead of "Hello world".

# test code my $a = 'use filtertest; BEGIN { print "eval test\n"; } sub { print "Hello word\n"; }->(); END { print "eval over\n" }'; eval $a;
# module: filtertest package filtertest; use Filter::Util::Call; sub import { my($type, @arguments) = @_; filter_add( sub { my($status); $status = filter_read(); s/word/world/g if ($status > 0); $status } ) } 1;

The problem is that I use eval to evaluate the code string. Actually, perl -e 'use filtertest; print "Hello word\n"' gives the same, i.e. wrong, result. But

use filtertest; print "Hello word\n";

works properly.

It seems the BEGIN magic of the filter is not executed when being 'eval'ed. Does this mean that Filter::Util::Call confilcts with the builtin eval function?

Thanks in advance. Feel free to correct my mistakes.

Replies are listed 'Best First'.
Re: Filter::Util::Call does not work in eval?
by Anonymous Monk on Sep 25, 2014 at 07:45 UTC

      Thanks a lot! I'll go through those threads :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2026-01-20 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (124 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.