Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Try::Tiny and -E

by haukex (Archbishop)
on Dec 26, 2025 at 12:56 UTC ( [id://11167011]=note: print w/replies, xml ) Need Help??


in reply to Try::Tiny and -E

Because -E implicitly enables all optional features and builtins, which as of 5.40 includes The 'try' feature, and AFAICT that try requires a catch.

Replies are listed 'Best First'.
Re^2: Try::Tiny and -E
by 1nickt (Canon) on Dec 26, 2025 at 13:35 UTC

    Thank you.


    The way forward always starts with a minimal test.

      Ways to address this:

      • You can convert to using the builtin feature.

        $ perl -E'try { 1/0 } catch ( $e ) { }; say "ok"' # Using 5.40 ok
      • You can follow add no feature qw( try );

        $ perl -MTry::Tiny -E'no feature qw( try ); try { 1/0 }; say "ok"' ok
      • You can use an older version of the "language" (even if you're using the 5.40 interpreter).

        $ perl -Mv5.38 -MTry::Tiny -e'try { 1/0 }; say "ok"' ok

        (5.10 would suffice for this program.)


      As you might have noticed, -E isn't forward compatible. Your program would have worked with 5.38, but it doesn't with 5.40. If it's not a throwaway program, it's safer to use

      -e'use v5.xx; ...'
      or
      -Mv5.xx -e'...'
      instead of
      -E'...' # XXX Not forward-compatible.

        You *could* also do this:
        perl -MTry::Tiny -E 'Try::Tiny::try { 1 / 0 } Try::Tiny::catch { print $_ };'
        which (as expected) generates:
        Illegal division by zero at -E line 1.

        Hope that helps.

        Thank you.


        The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

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

    No recent polls found

    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.