On Thursday 29 Apr 2010 18:56:08 marcos rebelo wrote: > the code: > > use v5.10; > use Modern::Perl; > use List::MoreUtils qw(any); > > say( (any { $_ eq 7 } (0..10) ) or 'false' ); > > given (5) { > when (5) { > say( (any { $_ eq 7 } (0..10) ) or 'false' ); > say( join(", ", map { $_ eq 7 } (0..10) ) ); > } > } >
I've brought it over on #p5p on irc.perl.org and here is the log: [log] Apr 29 19:11:50 --- Topic for #p5p is <@acme> 5.13.0 has been released and the code mines are open again Apr 29 19:11:50 --- Topic for #p5p set by acme!~a...@braga.cuckoo.org at Tue Apr 20 23:32:50 2010 Apr 29 19:14:31 <shadowpaste> "rindolf" at 217.168.150.38 pasted "Possible perl-5.10.1 bug from beginners@perl.org ." (39 lines) at http://paste.scsys.co.uk/42909 Apr 29 19:14:32 <dipsy> [ magnet_web paste from "rindolf" at 217.168.150.38... ] Apr 29 19:14:53 <rindolf> Hi all. Is this a perl-5.10.1+ bug? http://paste.scsys.co.uk/42909 Apr 29 19:14:55 <dipsy> [ magnet_web paste from "rindolf" at 217.168.150.38... ] Apr 29 19:16:00 <rindolf> Could be in List::MoreUtils::any though... Apr 29 19:16:34 <Bram> It's a known issue Apr 29 19:17:00 <Bram> given() creates a lexical $_. In ' any { $_ }' the global $_ is used. Apr 29 19:17:12 <rindolf> Bram: ah. Apr 29 19:17:25 <Bram> If I recall correct it is also mentioned in the perl5120delta Apr 29 19:17:52 <mst> so would $::_ work? Apr 29 19:18:02 <mst> I mean, I know it's fuck ugly, but. Apr 29 19:18:08 <Bram> http://perldoc.perl.org/perldelta.html#Known-Problems Apr 29 19:18:09 <dipsy> [ perldelta - perldoc.perl.org ] Apr 29 19:18:11 <Bram> No it wouldn't Apr 29 19:18:11 <rgs> our $_ Apr 29 19:18:20 <Zefram> perl -e 'use v5.10; use List::MoreUtils qw(any); given(5) { say( (any { $::_ eq 7 } (0..10) ) or 'false' ); }' Apr 29 19:18:21 <rindolf> Bram: it does. Apr 29 19:18:22 <purl> if you say so... Apr 29 19:18:27 <avar> The merge base f7c69158501ed4705d71f069f23211f56bd55a2e is bad. Apr 29 19:18:27 <avar> This means the bug has been fixed between f7c69158501ed4705d71f069f23211f56bd55a2e and [5348debf9fd57fc15c26529386769684fab96e57]. Apr 29 19:18:30 <avar> bisect run failed: Apr 29 19:18:35 <avar> hneegh, what's the fix for this again? Apr 29 19:18:54 <avar> oops paste Apr 29 19:19:11 <rindolf> mst: it works with $::_ Apr 29 19:19:39 <mst> rindolf: and rgs is right that 'our $_' would work as well which is likely less fucked up to use Apr 29 19:19:40 <Bram> Why does it work with $::_ ? Apr 29 19:19:53 <mst> Bram: because that's package var it looks it straight up from %main:: Apr 29 19:19:55 <Zefram> $::_ always refers to the global Apr 29 19:20:28 <Zefram> the problem was that in any { $_ eq 7 } ... the "$_" referred to the lexical $_, but the "any" function always presents the value to be tested in the global Apr 29 19:20:36 <rgs> $'_ Apr 29 19:20:46 <rgs> would be the shortest way to say it. Apr 29 19:20:55 * rgs gets his coat and goes home & Apr 29 19:20:56 <rindolf> rgs: heh. Apr 29 19:20:56 <Zefram> any { $::_ eq 7 } ... works regardless of lexical $_ existence Apr 29 19:21:00 <rindolf> rgs: bye Apr 29 19:21:37 <Bram> mst: yes, but IIRC given () sets the lexical $_, not the global $_... Apr 29 19:21:54 <Zefram> precisely Apr 29 19:21:55 <Bram> perl -wlE 'sub foo { my $code = shift; $code->(); } given (5) { print "lexical: $_, global: $::_"; foo( sub { print $::_ } ); }' Apr 29 19:22:13 <Zefram> given() doesn't just *set* the lexical $_, it *introduces* a lexical $_ Apr 29 19:22:15 <Bram> That prints lexical: 5, global: + undef Apr 29 19:22:58 <mst> Bram: which is EXACTLY what fixes the problem. Apr 29 19:23:16 <Bram> Oh right, ignore me. Apr 29 19:23:36 <Bram> I was confused for a couple of minutes... (I thought the goal was to access the lexical $_ of the given) [/log] Hope it helps. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Funny Anti-Terrorism Story - http://shlom.in/enemy God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/