I am trying to keep my distro Env::Dot backwards compatible to Perl 5.10.1. In order to do better error messaging, I have a nested evals which capture croaks from deeper in the program. Normal exception throw/catch stuff. I noticed this strange behavior in Perl 5.10.1:
#!/usr/bin/env perl
use strict;
use warnings;

use Carp;

local $@ = undef;
eval {
    local $@ = undef;
    eval {
        # croak __LINE__ . ':DEEPEST ERROR'; 1;
        croak 'DEEPEST ERROR'; 1;
    } or do {
        my $e = $@;
        warn __LINE__ . ":e=$e";
        croak $e;
    }; 1;
} or do {
    my $e = $@;
    warn __LINE__ . ":e=$e";
    croak $e;
};

Output:
16:e=DEEPEST ERROR at ./test-recursive-evals.pl line 13.
        eval {...} called at ./test-recursive-evals.pl line 14
        eval {...} called at ./test-recursive-evals.pl line 19
21:e= at ./test-recursive-evals.pl line 21.
 at ./test-recursive-evals.pl line 22.

In later Perl 5.14.4 this works as it should.

Is there a way around this bug, besides removing the nested evals? Or perhaps it is time to stop supporting older than 5.14 or 5.16?


In reply to Nested Evals in Old Perl 5.10 by mikkoi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.