in reply to Compare two signed integers without using comparision operator in perl

How to compare two signed integers without using the comparision operators in perl.
So what's a signed integer? I know of scalars, and a few ways to force a scalar to be considered some sort of integer, but why "signed" integer? Perl doesn't care.


Perl programming and scheduling in the corporate world, as explained by dragonchild:
"Uhh ... that'll take me three weeks, broken down as follows: 1 day for coding, the rest for meetings to explain why I only need 1 day for coding."
  • Comment on Re: Compare two signed integers without using comparision operator in perl

Replies are listed 'Best First'.
Re: Re: Compare two signed integers without using comparision operator in perl
by bart (Canon) on May 06, 2003 at 19:15 UTC
    You can use string comparison on positive, unsigned integers, or even unsigned floating point numbers, if you make sure the number of digits left of the decimal point (if any) are the same for all numbers. Thus, after using sprintf with a proper template.

    This doesn't work if at least one of the numbers is negative.

    I don't think it matters for this particular case, as string comparison is comparison nevertheless, but still... It's the only reason I can think of why the sign would matter.

    p.s. It's even an excellent way to compare groups of strings/numbers in one comparison, for example, for sort.