#1: Stop the mail to me

Posted on 2011-10-07 12:24:18 by ganesh vignesh

Stop mail

On 10/6/11, Chris Stinemetz <chrisstinemetz@gmail.com> 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
http://learn.perl.org/

Report this message

#2: Re: Stop the mail to me

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

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

Read the footer of the mail

--bcaec51f900f06bd0e04aeb3207f--

Report this message

#3: Re: Stop the mail to me

Posted on 2011-10-07 12:46:02 by 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
http://learn.perl.org/

On Fri, Oct 7, 2011 at 6:24 AM, ganesh vignesh <vigneshganesh08@gmail.com>wrote:

> Stop mail
>
> On 10/6/11, Chris Stinemetz <chrisstinemetz@gmail.com> 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--

Report this message