Re: usage of do {}
- From: daggerquill@xxxxxxxxx (Jay Savage)
- Date: Thu, 30 Jun 2005 12:14:09 -0400
On 6/30/05, Wiggins d'Anconia <wiggins@xxxxxxxxxxxx> 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
.
- Follow-Ups:
- Re: usage of do {}
- From: Dave Gray
- Re: usage of do {}
- References:
- usage of do {}
- From: Peter Rabbitson
- Re: usage of do {}
- From: Wiggins d'Anconia
- usage of do {}
- Prev by Date: Re: usage of do {}
- Next by Date: Use of uninitialized value... --> quit!
- Previous by thread: Re: usage of do {}
- Next by thread: Re: usage of do {}
- Index(es):