in reply to Could someone please explain this to me in newbie terms :)

A good quick reference on the operators involved can be found at perlop. Breaking down your two expressions:

$z = $y ? $x / $y : 0;

  1. Given the ternary Conditional Operator, start with the conditional term.
  2. In Perl, 0 is equivalent to false for logical operators (as are nulls/undefs), so that term is equivalent to $y!=0
  3. If $y is not zero, the ternary returns $x/$y
  4. If $y is zero, the ternary returns 0;
  5. Lastly, $z gets the value returned by ? :

$z = $y && $x / $y;

  1. Given the binary C style Logical And, start with the first term.
  2. If $y == 0, the first term is false, so return false/0.
  3. If $y != 0, the first term is true so evaluate the second term.
  4. If $x / $y == 0, the second term is false, so return false/0.
  5. If $x / $y != 0, the second term is true, so return true.
  6. When && returns true, it returns the return value of the last expression in the chain, hence $x / $y.

Hope that's clear...

Replies are listed 'Best First'.
Re^2: Could someone please explain this to me in newbie terms :)
by Anonymous Monk on Aug 08, 2009 at 08:32 UTC
    To be explicit, $z = $y && $x / $y; construct assigns the value of $y to $z, not necessarily a zero unlike $z = $y ? $x / $y : 0;.
      ... when $y evaluates to a false truth value.