On Wed, Feb 09, 2011 at 06:14:31PM -0500, Bernhard Graf via RT wrote:
Show quoted text> Wed Feb 09 18:14:30 2011: Request 65603 was acted upon.
> Transaction: Ticket created by GRAF
> Queue: Try-Tiny
> Subject: $_ fails in switch stmt
> Broken in: 0.09
> Severity: Normal
> Owner: Nobody
> Requestors: GRAF@cpan.org
> Status: new
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=65603 >
>
>
> Try this one:
>
> use feature ':5.10';
> use Try::Tiny;
>
> # as usual
> try { die "foo" } catch { warn "Got a die: $_" };
>
> # no within a "switch"
> given ("bar") {
> when ("bar") {
> try { die "foo" } catch { warn "Got a die: $_" }
> }
> }
>
The 'given' keyword lexicalizes $_, and lexical $_ takes precedence over
global $_. As far as I know, there's nothing that we can actually do to
fix this (although ideas are welcome), but you can work around it by
either using $_[0] (which will have the same value as $_) or by
explicitly qualifying the global access, like $::_.
-doy