What's the best practice in case something goes wrong in Perl code?

Posted by Geo on Stack Overflow See other posts from Stack Overflow or by Geo
Published on 2010-03-07T11:25:47Z Indexed on 2010/03/08 4:36 UTC
Read the original article Hit count: 143

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?

© Stack Overflow or respective owner

Related posts about perl

Related posts about exception-handling