Simple Negative Number Checking Subroutine in Perl

Discussion in 'Perl' started by pradeep, Oct 30, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Many times we need to check whether a number is negative or not, here is a very simple subroutine to do that.

    Code:
    sub isNegative 
     {
         my($checkValue) = @_;
         if(abs($checkValue) != $checkValue) 
         {
             # the value is negative
             return 1;
         } 
         else 
         {
             # number is positive
             return 0;
         }
     }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice