Hi Chris,
 I think you will need to work on your code to make it better or maybe this
is just a dirty codes for practice. If not, there are some stuff you may
have to weed out...some of which Shlomi Fish mentioned.

However, to make your code work as you suppose, please check this little
addition and you can take it up from there.

<code>
#!/usr/bin/perl

use warnings;
use strict;
use 5.010;

say "Checking the number <$ARGV[0]>";

my $favorite = 62;

given( $ARGV[0] ) {
       when( ! /^\d+$/ ) { say "Not a number!" }

       my @divisors = divisors( $ARGV[0] );
        my $val=2;   #added test value
       when( @divisors ~~  /$val/) { # 2 is in @divisors ,/$val/ check it
               say "$_ is even";
               continue;
               }

       when( !( @divisors ~~/$val/ ) ) { # 2 isn't in @divisors /$val/ check
it
               say "$_ is odd!";
               continue;
               }

       when( @divisors ~~ /$favorite/ ) { # /$favorite/ check it
               say "$_ is divisible by my favorite number";
               continue;
               }

       when( /$favorite/ ) { # $_ ~~ $favorite
               say "$_ is my favorite number";
               continue;
               }

       my @empty;
       when( @divisors ~~ @empty ) { say "Number is prime" }

       default { say "$_ is divisible by @divisors" }
       }

sub divisors {
       my $number = shift;

       my @divisors = ();
       foreach my $divisor ( 2 .. ($ARGV[0]/2 + 1) ) {
               push @divisors, $divisor unless $number % $divisor;
               }

return @divisors;
}
</code>

Regards,
timothy

Reply via email to