7stud has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use 5.010; my @numbers = (2); my @other = (2); if (@numbers ~~ @other) { say 'yes' }else{ say 'no'; } #output: yes if (@numbers ~~ (2)) { say 'yes' }else{ say 'no'; } #no
That problem came up when I tried to check whether an array was empty in a given-when:
given (@arr) { when (()) {say "The array is empty."} when (34) {say "The array contains 34."} default {say "Something else."} }
It seems kind of lame to have to do this:
given (@arr) { my @empty = () when (@empty) {say "The array is empty."} when (34) {say "The array contains 34."} default {say "Something else."} }
Can we send the smart operator back to school?
...and now I see I have problems with the second when too. This doesn't work at all for me:
my @arr1 = (2, 34); say "34" if @arr1 ~~ 34; #no output...??
This doesn't work either:
my @arr1 = ('hello', 'goodbye'); say "array size is 2" if @arr1 ~~ 2; #no output
|
|---|