Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Eval not trapping fatal error

by Ea (Chaplain)
on Dec 07, 2015 at 12:26 UTC ( [id://1149570]=note: print w/replies, xml ) Need Help??


in reply to Re: Eval not trapping fatal error
in thread SOLVED: Eval not trapping fatal error

Of course, you're right.

So, while other constant modules may die and be trapped with eval BLOCK, the constant pragma makes assignment a syntax error and needs to be trapped with eval EXPRESSION. Now I understand the line in the book

the code in the BLOCK has to be valid Perl code to make it past the compilation phase
Thanks

Sometimes I can think of 6 impossible LDAP attributes before breakfast.

http://act.yapc.eu/lpw2015/ It's that time of year again!

Replies are listed 'Best First'.
Re^3: Eval not trapping fatal error
by Corion (Patriarch) on Dec 07, 2015 at 12:34 UTC

    I don't think that you can trap other constant modules with a block eval either. The issue lies with Perl, which doesn't allow a function/subroutine on the left-hand side of an assignment, unless that function is already known as assignable through the :lvalue attribute:

    > perl -wle "sub foo {}; eval { foo()='baz' }" Can't modify non-lvalue subroutine call in scalar assignment at -e lin +e 1, near "'baz' }" Execution of -e aborted due to compilation errors.

    Marking the subroutine with :lvalue lets Perl know that we intend to let the function appear on the left-hand side of an assignment:

    > perl -wle "sub foo:lvalue {}; eval { foo()='baz' }"

    All "constant" modules are syntactic sugar for defining functions that take no parameters, because that's how sigil-less constants work in Perl.

Log In?
Username:
Password:

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

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

    No recent polls found