What are the common pitfalls associated with Perl\'s eval, which might make you choose to use a module such as Try::Tiny?
In addition to the answers above, I would add...
$SIG{__DIE__}
handler causing action at a distance.eval BLOCK
and eval STRING
, since they appear to do the same thing, but one is a security hole.Try::Tiny has its own pitfalls, the biggest being that while it looks like a block it is actually a subroutine call. That means this:
eval {
...blah blah...
return $foo;
};
and this:
try {
...blah blah...
return $foo;
};
do not do the same thing. These are laid out in the CAVEATS section of the Try::Tiny docs. That said, I'd recommend it over eval
.