lestrrat has asked for the wisdom of the Perl Monks concerning the following question:
I'm in a dilemma here. At work, we have a lot of C programmers, and hence they like to code their Perl code in sort of a C-ish way. Which is fine in most cases, but there's one thing that I just fail to see the benefit, and that is an idiom that they use:
sub myfunc { ... return eval { # do bunch of things here... if($err_condition) { die "error"; } return 1; } }
So basically they want to make it such that you can check the return value and check $@ in an errono-like fashion. Which is fine, but it just strikes me as really, really odd.
I just fail to see how it could be better than just simply raising an exception. Why can't I just die()?
If I'm to try and use a simple die/croak instead, I'm going to have to convince a lot of people... Otherwise if I'm going to have to live with it, I want to make sure that I understand the benefits, and that we're not alone in using this.
In all honesty, I may just be too deep into all the Perl-isms, and that I'm missing something obvious. If there are other people who use this idiom, I would realy like to know, and also, why? What advantages do you gain?
TIA.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: return eval { die() } idiom
by tcf22 (Priest) on Aug 29, 2003 at 19:36 UTC | |
by lestrrat (Deacon) on Aug 29, 2003 at 19:42 UTC | |
by monsieur_champs (Curate) on Aug 29, 2003 at 21:05 UTC | |
by tcf22 (Priest) on Aug 29, 2003 at 19:54 UTC | |
|
Re: return eval { die() } idiom
by benn (Vicar) on Aug 30, 2003 at 10:08 UTC | |
|
Re: return eval { die() } idiom
by bsb (Priest) on Aug 30, 2003 at 15:17 UTC | |
by dragonchild (Archbishop) on Sep 02, 2003 at 15:43 UTC |