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

Maybe I ate too much turkey yesterday, but ... using perl 5.40.1, why does this code work:

$ perl -MTry::Tiny -e 'try {1/0};' $
while this code gets an error:
$ perl -MTry::Tiny -E 'try {1/0};' syntax error at -e line 1, near "};" Execution of -e aborted due to compilation errors. $
Thanks.


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: Try::Tiny and -E
by haukex (Archbishop) on Dec 26, 2025 at 12:56 UTC

      Thank you.


      The way forward always starts with a minimal test.
Re: Try::Tiny and -E
by LanX (Saint) on Dec 26, 2025 at 13:34 UTC
    -E activates all features and try/catch is one of them.

    The parser is most likely expecting the catch{} part after try{}

    I think Try::Tiny should attempt to warn you or die.

    You might want to open a ticket.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    (As of 2025-12-26 12:59 GMT, not sure when this post will get thru...)

        Thank you.

        In hindsight it might be that Try::Tiny is complied before the -E takes effect.

        Not sure about the compilation order here. °

        In that case only something like an INIT {} block could catch the conflict.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        °) redefining a built-in should fail...