in reply to Re^6: why is my for loop using modulo giving me a weird output
in thread why is my for loop using modulo giving me a weird output
See for yourself:
#!/usr/bin/perl use strict; my $i = 1; my ($quo1, $rem1) = ($i/5, $i%5); #need to understand modulo print "Without int: Quotient = [$quo1], Remainder = [$rem1]\n"; my ($quo2, $rem2) = (int($i/5), $i%5); #modified to use int print " With int: Quotient = [$quo2], Remainder = [$rem2]\n"; exit; __END__
Results:
D:\PerlMonks>modulo1.pl Without int: Quotient = [0.2], Remainder = [1] With int: Quotient = [0], Remainder = [1] D:\PerlMonks>
|
|---|