What's the best practice in case something goes wrong in Perl code?
exception, perl
Solution
Block `eval` isn't string `eval`, so no, it's not slow. Using it is definitely recommended.
There are a few annoying subtleties to the way it works though (mostly annoying side-effects of the fact that `$@` is a global variable), so consider using Try::Tiny instead of memorizing all of the little tricks that you need to use `eval` defensively.
Problem
Possible Duplicates: How can I cleanly handle error checking in Perl? What’s broken about exceptions in Perl? I saw code which works like this: ``` do_something($param) || warn "something went wrong\n"; ``` and I also saw code like this: ``` eval { do_something_else($param); }; if($@) { warn "something went wrong\n"; } ``` Should I use eval/die in all my subroutines? Should I write all my code based on stuff returned from subroutines? Isn't `eval`'ing the code ( over and over ) gonna slow me down?