Part Three: Arithmatic Functions

Though Perl has an extensive mathmatics toolbox, I don't tend to use these features to their utmost potential. I will admit, I am more likely to work with strings than I am numbers. Yet, from time to time, I do need to crunch a few numbers.

Please Note:

  • As a Quick & Dirty Guide (QDG), this document is not meant as a tutorial, but as a reference.
  • This web page is generated by a Perl script. The actual code listed in the examples is executed to generate the output shown.
  • Many of the examples contain <br>\n. This is not part of Perl, but is included to format output to a console or browser.
  • The narrow width of the examples allows for easier export to mobile computing platforms, such as Palm and 3G devices.
      -----------------------------------------------------
    $new = $one + $two
    Arithmatic equation: +, -, *, /, ()
     $j=$one+$two;
     print"+=$j ";
     $k=$two*$j;
     print"*=$k ";
     $j=$k-$one;
     print"-=$j ";
     $k=$j/$two;
     print"/=$k ";
     $j=$one+($two*$k);
     print"()=$j ";
    +=3 *=6 -=5 /=2.5 ()=6
    -----------------------------------------------------
    abs($value)
    Returns absolute value.
     $j=-3.1415;
     print"J: $j ";
     $j=abs($j);
     print"$j ";
    J: -3.1415 3.1415
    -----------------------------------------------------
    int($value)
    Returns integet value.
     print"J: $j ";
     $j=int($j);
     print"$j ";
    J: 3.1415 3
    -----------------------------------------------------
    rand
    Generates a number between 0 and 1.
     print"J: $j ";
     $k=rand;
     print"$k ";
     print int($k*$j+1);
    J: 3 0.202399670452909 1
    -----------------------------------------------------
    sleep($value)
    Pauses execute, in seconds.
     sleep(2);

    Done.