Stop the mail to me

Stop the mail to me

am 07.10.2011 12:24:18 von ganesh vignesh

Stop mail

On 10/6/11, Chris Stinemetz wrote:
> trying to learn smart matching in an exercise.
>
> Why does this program output "odd" when I input an even number?
>
> Thank you,
>
> Chris
>
> #!/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] );
>
> when( @divisors ~~ 2 ) { # 2 is in @divisors
> say "$_ is even";
> continue;
> }
>
> when( !( @divisors ~~ 2 ) ) { # 2 isn't in @divisors
> say "$_ is odd!";
> continue;
> }
>
> when( @divisors ~~ $favorite ) {
> 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;
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--
Sent from my mobile device

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

Re: Stop the mail to me

am 07.10.2011 12:44:26 von Ramprasad Prasad

--bcaec51f900f06bd0e04aeb3207f
Content-Type: text/plain; charset=ISO-8859-1

>
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>



Read the footer of the mail

--bcaec51f900f06bd0e04aeb3207f--

Re: Stop the mail to me

am 07.10.2011 12:46:02 von Sheppy R

--0016364ed40eb9c74104aeb325c7
Content-Type: text/plain; charset=ISO-8859-1

Stop spamming us with stop mail requests and use the instructions included
at the bottom of the email to unsubscribe.

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

On Fri, Oct 7, 2011 at 6:24 AM, ganesh vignesh wrote:

> Stop mail
>
> On 10/6/11, Chris Stinemetz wrote:
> > trying to learn smart matching in an exercise.
> >
> > Why does this program output "odd" when I input an even number?
> >
> > Thank you,
> >
> > Chris
> >
> > #!/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] );
> >
> > when( @divisors ~~ 2 ) { # 2 is in @divisors
> > say "$_ is even";
> > continue;
> > }
> >
> > when( !( @divisors ~~ 2 ) ) { # 2 isn't in @divisors
> > say "$_ is odd!";
> > continue;
> > }
> >
> > when( @divisors ~~ $favorite ) {
> > 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;
> >
> > --
> > To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> > For additional commands, e-mail: beginners-help@perl.org
> > http://learn.perl.org/
> >
> >
> >
>
> --
> Sent from my mobile device
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--0016364ed40eb9c74104aeb325c7--