in reply to Re^2: Question on "Effective Perl Programming" (;1 > $@)
in thread Question on "Effective Perl Programming"

package DESTROY::EVAL_ERROR::NOT; my %done; sub import { shift @_; for my $pkg ( @_ ) { next if $done{$pkg}++; $pkg .= "::DESTROY"; my $orig= \&{$pkg}; no warnings; *{$pkg}= sub { local $@; $orig->(@_) }; } }

Then:

use Broken::Package; use DESTROY::EVAL_ERROR::NOT qw( Broken::Package ); ...

In other words, "if I can't change EvalEater" need never be true. :)

- tye        

Replies are listed 'Best First'.
Re^4: Question on "Effective Perl Programming" (intervene)
by Anonymous Monk on Sep 07, 2007 at 13:11 UTC
    If it takes so much to check that an eval worked, maybe something should be fixed?
      How is this:
      my $worked = eval {stuff}; if ($worked) { print "Yay!"; } else { print "Boo!: $@"; }

      so much to check an eval? That's all you really need to do.
        "stuff" might return false, but not be an eval error, thus to paraphrase some other post of tye's:
        my $worked = eval { stuff; 1; };
        Of course, then you lose the return value of stuff if you cared about it, though you could save it in another variable if you want to go through the trouble.

        The big problem I have with the behavior that tye illuminates is that you can't tell what the exception was, only that something happened.