Skip Menu |

This queue is for tickets about the Try-Tiny CPAN distribution.

Report information
The Basics
Id: 65603
Status: resolved
Priority: 0/
Queue: Try-Tiny

People
Owner: Nobody in particular
Requestors: GRAF [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.09
Fixed in: (no value)



Subject: $_ fails in switch stmt
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: $_" } } }
Subject: Re: [rt.cpan.org #65603] $_ fails in switch stmt
Date: Wed, 9 Feb 2011 18:05:35 -0600
To: Bernhard Graf via RT <bug-Try-Tiny [...] rt.cpan.org>
From: Jesse Luehrs <doy [...] tozt.net>
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
Thanks Jesse for the explanation. Will RTFM next time. ;) Bernhard