Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Yes, this is a well-known problem with eval. You cannot, as the manual page suggests, do eval { ... } and then test $@ to see whether there was an error. The correct incantation is something like

    my $r = eval { ... };
    my $error = $@;
    $error //= 'unknown error' if not $r;
    if ($error) { ... }

    By well-known I mean known to a tiny minority of cognoscenti, while most perl programmers and the documentation are entirely ignorant of it. Which is the default situation for any trap or gotcha in the perl language. But
    --
    -- Ed Avis ed@membled.com
    • Duuh, I meant

      my $r = eval { ...; 1 };
      my $error = $@;
      $error //= 'unknown error' if not $r;
      if ($error) { ... }

      Note the trailing '1' in the eval block.

      (It doesn't help that the comment engine here is doing something weird so you lose all your text if you go Back and Forward in Firefox. And those submit buttons are not buttons at all but look like links. What's going on?)
      --
      -- Ed Avis ed@membled.com