On 6/30/05, Wiggins d'Anconia <[EMAIL PROTECTED]> wrote:
> Peter Rabbitson wrote:
> > Hello everyone,
> > Here and there on the web I encounter claims that the do {} operator is
> > depreciated. However I find it convenient to do things like:
> >
> > eval { some stuff } or do { some multiline error handling };
> >
> > is this a bad practice?
> >
> > Thanks
> >
> > Peter
> >
> >
> 
> Didn't see anything about 'do' being deprecated in the perldoc -f do or
> perldoc perlsyn docs. Though do SUBROUTINE was stated as deprecated.
> The problem (IMHO) with the above is that you can't return a positive
> value from the eval and you haven't error checked whether there was an
> exception thrown, which is one of the more common reasons to use an eval
> in the first place. So I guess my question is, why are you using the
> eval to begin with?
> 
> my $return = eval { some stuff };
> if ($@) {
>   rethrow or handle "Eval failed with: $@";
> }
> unless ($return) {
>   some multiline error handling;
> }
> 
> The problem is that eval returning a false/undefined value shouldn't
> necessarily have to indicate failure. And if the 'eval' isn't catching
> an exception then there is really no reason to use it in the first place.
> 
> http://danconia.org
> 
> 

That's not entirely true: eval is also useful for delaying execution
(module inclusion, etc.) until runtime.

Checking for $@, though, is a must no matter what you're using it for.

-- jay
--------------------
daggerquill [at] gmail [dot] com
http://www.tuaw.com
http://www.dpguru.com
http://www.engatiki.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to