Re: How to check if a DateTime is invalid (again - but this time without using eval)?
[email protected] (Dave Rolsky) Tue, 11 Jul 2017 11:12:50 -0500
| Newsgroups | perl.datetime |
|---|---|
| Message-ID | <CAHKw1MLmJdKwA9qJpELi02oTt4b9WVm77Yp-CfnnpFzcNJHr1A@mail.gmail.com> |
On Tue, Jul 11, 2017 at 10:56 AM, Paul Hoffman <[email protected]> wrote: > On Mon, Jul 10, 2017 at 09:44:15PM +0100, Zefram wrote: > > Thomas (HFM) Wyant wrote: > > >One of the edge cases with eval {} is the possibility that $@ gets > > >clobbered before you get your hands on it. > > > > The possibility of it being clobbered by a destructor was fixed in 5.14. > > (Destructors that do this are considered buggy, for pre-5.14 perls, > > and are individually easy to fix, so the problem is still manageable on > > those perl versions.) > > And in perl < 5.14 you can work around it easily enough: > > my $ok; > eval { > ... > $ok = 1; > }; > if ($ok) { > ... > } > I'd write that as ... my $ok = eval { ...; 1 }; if ($ok) { ... } I think that reads a little better. Of course, I'd also just use Try::Tiny and use a catch instead of checking $ok in the first place.