for integers you can simply use the "mod" operator %

if (0==$number%2) {
        #no remainder so it's even
}else{
        #odd
}


from perldoc perlop
Binary ``%'' computes the modulus of two numbers. Given integer operands $a
and $b: If $b is positive, then $a % $b is $a minus the largest multiple of
$b that is not greater than $a. If $b is negative, then $a % $b is $a minus
the smallest multiple of $b that is not less than $a (i.e. the result will
be less than or equal to zero). Note that when use integer is in scope,
``%'' gives you direct access to the modulus operator as implemented by your
C compiler. This operator is not as well defined for negative operands, but
it will execute faster.


Kind regards,

Mark Anderson
Service Improvement Project
Level 2, 113 Dundas Street
Edinburgh, EH3 5DE
Tel: 0131 523 8786
Mob: 07808 826 063


> -----Original Message-----
> From: Leroy G. Blimegger Jr. [SMTP:[EMAIL PROTECTED]
> Sent: Monday, November 22, 2004 10:42 AM
> To:   'Perl Win32 Forum (ActiveState)'
> Subject:      Odd, Even, or Multiple of a number
> 
> *** WARNING : This message originates from the Internet ***
> 
> Hello,
> 
> Here's what I have:
> 
> I have a perl script with a while loop that performs some analysis on
> several thousand text records.
> I have a VB frontend that runs the perl script (and the perl script passes
> information back to the VB frontend via a TCP socket
> 
> Here's the problem:
> 
> I'm implementing a progress bar in my VB frontend. When I pass the loop
> count back to VB, the socket chokes (because the loop is too fast). I
> don't
> want to buffer or slow down the loop. What I would like to do is have some
> sort of if statement in the loop that passes the loop count (print
> $socket)
> only under certain conditions, like if the loop count is odd, or even, or
> a
> multiple of some number (say 10, 0r 100). Is there a perl function that
> allows me to determine if a number is odd, or even, or a multiple of
> another
> number?
> 
> Thanks
> 
> Lee
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered 
Office: 36 St Andrew Square, Edinburgh EH2 2YB

The Royal Bank of Scotland plc is authorised and regulated by the Financial 
Services Authority and represents The Royal Bank of Scotland Marketing Group. 
The Bank sells life policies, collective investment schemes and pension 
products and advises only on the Marketing Group's range of these products and 
on a With-Profit Bond produced by Norwich Union Life (RBS) Limited.

This e-mail message is confidential and for use by the addressee only. If the 
message is received by anyone other than the addressee, please return the 
message to the sender by replying to it and then delete the message from your 
computer. Internet e-mails are not necessarily secure. The Royal Bank of 
Scotland plc does not accept responsibility for changes made to this message 
after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, 
it is the responsibility of the recipient to ensure that the onward 
transmission, opening or use of this message and any attachments will not 
adversely affect its systems or data. No responsibility is accepted by The 
Royal Bank of Scotland plc in this regard and the recipient should carry out 
such virus and other checks as it considers appropriate.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to