On Nov 27, 2010, at 9:01 AM, Chap Harrison wrote: > On Nov 27, 2010, at 7:45 AM, Téssio Fechine wrote: > >> Why "@divisors ~~ 2" is not true? > > No idea - it seems to work fine for me: > - - - > /Users/chap/private/perl$ cat smart > use 5.010; > use strict; > use warnings; > > my @divisors = (1, 2); > > say "It's divisible by 2!" if @divisors ~~ 2; > - - - > /Users/chap/private/perl$ perl smart > It's divisible by 2! > > /Users/chap/private/perl$ perl -v > > This is perl, v5.10.0 built for darwin-thread-multi-2level
Ah - are you running 5.12? I tried running the above with Perl 5.12, and replicated your behavior. Smart matching changed with 5.12: chap-VirtualBox:/home/chap/private/perl$ cat smart - - - use 5.010; use strict; use warnings; my @divisors = (1, 2); say "Array~~Scalar: It's divisible by 2!" if @divisors ~~ 2; say "Scalar~~Array: It's divisible by 2!" if 2 ~~ @divisors; - - - chap-VirtualBox:/home/chap/private/perl$ perl smart # running Perl 5.12.2 Scalar~~Array: It's divisible by 2! Offhand I don't see exactly what accounts for the new behavior, apart from the non-commutativity that was introduced. It is probably covered here, but I'm not seeing it. http://search.cpan.org/~jesse/perl-5.12.2/pod/perl5120delta.pod#Smart_match_changes Regards, Chap -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/