xzatech has asked for the wisdom of the Perl Monks concerning the following question:

I hope my question is a simple one for you, for me it has been not. if you have the time the % in perl what is it doing insomething like this $number %2 == 1

i used it in the following but want to understand what it is actually doing
#!/usr/bin/perl print "\tPick a number\n"; $number = <>; if($number %2 == 1){ print "That was a odd number\n"} else { print "That was a even number\n"} exit
as I have read theres no s for string no g for floating point no d for decimal so by itself what is it doing and how is it making this work .. no where have i found info on % by itself with a number .

Replies are listed 'Best First'.
Re: % in perl
by boblawblah (Scribe) on Feb 10, 2009 at 22:23 UTC
    The modulus operator gives you the remainder in division. So...
    22 % 5 = 2
    because 22 divided by 5 is 4 and 2/5 or 4 and a remainder of 2.

    Also, you should put code between <code> </code> tags. I suggest you read this.
Re: % in perl
by jdporter (Paladin) on Feb 10, 2009 at 21:44 UTC

    It's the mathematical modulus operator. It is documented in Multiplicative Operators, but that explanation is more smoke than light.

    Between the mind which plans and the hands which build, there must be a mediator... and this mediator must be the heart.
Re: % in perl
by syphilis (Archbishop) on Feb 10, 2009 at 23:53 UTC
    no where have i found info on % by itself with a number

    Run perldoc perlop and look for the "Multiplicative Operators" section.

    Cheers,
    Rob
A reply falls below the community's threshold of quality. You may see it by logging in.