[D]perl 小程序求修改(5)
use 5.010;print "please input a number\n";$favorate=13;chomp($num=<STDIN>);given($num){ when (!/^\d+$/) {print "is not a number\n"} @div=&divisors($_); @empty; when (@div~~@empty){print"number is prime and is odd\n"} when (@div~~2){print "this is an even\n";continue} when (!(@div~~2)) {print "this is an odd\n";continue}; when (@div~~$favorate){print "This number can be divided by $favorate\n";continue} when (!(@div~~$favorate)){print "this number can not be divided by $favorate\n"} default {print"$_ is divisible by @divisors"} }sub divisors { my $number=shift; my @divisors=(); foreach my $divisor (2..($number/2)) { push @divisors, $divisor unless $_ % $divisor; }return @divisors;}
push @divisors, $divisor unless $num % $divisor;