my @divisors = (1, 2);

say "It's divisible by 2!" if @divisors ~~ 2;

How do you think that would work?
From perldoc perlop:

       Binary "~~" does a smart match between its arguments. Smart
       matching is described in "Smart matching in detail" in perlsyn.


my @divisors = (1 .. 6);
for my $i(@divisors) {
  if(i % 2 == 0) {
    print "$i is divisible by 2\n";
  }
}

if(3 ~~ @divisors) {
  print "value 3 exists in \...@divisors\n";
}

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to