Algebra

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beany
    New Member
    • Nov 2006
    • 173

    Algebra

    Hi,

    algebra: z = pr%q+w/x - y

    Perl code for this is: $z = $p * $r % $q + $w / $x - $y;

    Can someone please explain to me : in what order does Perl calculate the operators? What would be calculated first, second, third etc... why?

    I just cant get my head around the algebra business..
    How does perl simplify the above algebra?
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by Beany
    Hi,

    algebra: z = pr%q+w/x - y

    Perl code for this is: $z = $p * $r % $q + $w / $x - $y;

    Can someone please explain to me : in what order does Perl calculate the operators? What would be calculated first, second, third etc... why?

    I just cant get my head around the algebra business..
    How does perl simplify the above algebra?
    What you are looking for is the "order of operations" for Perl. Perl always processes things in a pre-defined order. A quick google search reveals plenty of links or, you can open your copy of Learning Perl or any other basic Perl book and read about it.

    Regards,

    Jeff

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Its the same as math:

      First do anything in parentheses
      Then do any multiplication or division working left to right
      then do any addition or subtraction working left to right

      Why would you think perl would do it any different? If it did then the answer has the potential of not being correct.

      Comment

      Working...