[Milan-pm] [mongers-it] Is this a feature or a bug?
Emanuele Zeppieri
ema.zep at libero.it
Thu Apr 29 11:50:31 PDT 2010
On 29/04/2010 17.56, 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) ) );
> }
> }
>
>
> prints:
>
> 1
> false
> , , , , , , , 1, , ,
>
>
>
> the second 'any' should have returned a true value or not, and why???
The diagnosis given by Flavio (Poletti from mongers at perl.it) is correct,
so just declare "our $_" to restore the global $_:
given (5) {
when (5) {
say( any { our $_ eq 7 } 0..10 or 'false' );
say( join ', ', map { $_ eq 7 } 0..10 );
}
}
prints:
1
, , , , , , , 1, , ,
as expected.
Not that clear but, given the perlsyn fragment pointed out by Flavio, it
works as advertised.
Ciao
-Emanuele
More information about the Milan-pm
mailing list