develooper Front page | perl.perl5.porters | Postings from March 2003

Re: [perl #21770] modulus function not working for negative numbers

Thread Previous
Benjamin Goldberg
March 31, 2003 14:14
Re: [perl #21770] modulus function not working for negative numbers
Message ID:
"Schulte, David (Dave)" wrote:
> Just a follow up. Although Perl is returning the mathematical concept
> of a modulus value, it is not returning a integer arithmetic value of
> a remainder, which is what C returns.

It does use the C modulo operator *if* the 'use integer' pragma is in

> The Perl book by O'Reilly & Associates, Inc. states that Perl's %
> operator will return a remainder according to integer division, which
> clearly it is not.

Dead trees are not the primary documentation for perl.

The primary documentation for perl is the .pod files which come with
perl, and are accessible through the "perldoc" program.

The primary documentation for perl operators is the "perlop.pod" file,
which you can read by running "perldoc perlop" from the commandline.

> Lesson learned, avoid negative operands.

Wrong lesson learned.  The right lesson would be to read the right
documentation -- "perldoc".

$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About