On Fri, Jul 26, 2013 at 7:07 AM, David E. Wheeler <david@justatheory.com>wrote: > On Jul 26, 2013, at 1:56 AM, David Nicol <davidnicol@gmail.com> wrote: > > >> package Foo { > >> CATCH { > >> # BOOM. > >> } > >> } > > > > that looks like it should get optimized out, with a warning: AFAIK > > Perl has no syntax construct at this time that would change the scope > > of something depending on if something else is there or not. > > > > package Foo { > > CATCH { > > ... recovering from Foo:: error ... > > } > > } > > package Foo { > > sub riskything{ > > ... > > }; > > CATCH { > > ... recovering from error in Foo::riskything() > > } > > } > > Yeah, that’s what I meant. Should also allow: > > package Foo { > use Bar; > my $f = Bar->baz; > CATCH { > # Recover from error anywhere in Foo > } > } > I'm happy I understood you correctly. I think changing the scope of something based on whether or not enough other stuff appears between the curlies too is a bad idea, and that the CATCH in the last of the above examples should only handle tantrums thrown in Bar->baz. Due to the implied BEGIN around the C<use> the CATCH won't handle tantrums originating in Bar.pm's inclusion and import, but it should if it precedes it.Thread Previous | Thread Next