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

print $a, ' is ', ('smaller', 'equal', 'greater')[1+($a<=>$b)], ' than + ', $b;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
  • Comment on Re: Compare two signed integers without using comparision operator in perl
  • Download Code

Replies are listed 'Best First'.
Re: Re: Compare two signed integers without using comparision operator in perl
by BrowserUk (Patriarch) on May 07, 2003 at 01:30 UTC

    FWIW, the in the OP's clarification of this question, the list of excluded operators was  ==,<,>. The way I read the clarification and the original question, I believe that <=> was not excluded, and could well have been what the OP was looking for, rather than the mathematical monstrocitoes offered.

    C'est la vie.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller