Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test is a string is a multiple of 4 2

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello, wondering how to go about testing a string to see if it's a multiple/multiplier of 4. I want to be able to ensure that the string that I am working with is always going to be able to be divided by four if not then I would like to ignore it.

thanks for the help in advanced.
 
Code:
if ( ($n / 4) <= 0 ) {
    print "$n is not divisible by four: $dv\n";
}
else {
    print "$n is divisible by four: $dv\n";
}

 
Wish I could edit...

main point is:

Code:
if ( ($n / 4) <= 0 ) {
 
Modulus operator '%' returns the remainder of division. You can use that to test for a true/false return value:

Code:
if ($n % 4) {
  print "Not divisor of 4 because there is a remainder\n";
}

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top