A good quick reference on the operators involved can be found at
perlop. Breaking down your two expressions:
$z = $y ? $x / $y : 0;
- Given the ternary Conditional Operator, start with the conditional term.
- In Perl, 0 is equivalent to false for logical operators (as are nulls/undefs), so that term is equivalent to $y!=0
- If $y is not zero, the ternary returns $x/$y
- If $y is zero, the ternary returns 0;
- Lastly, $z gets the value returned by ? :
$z = $y && $x / $y;
- Given the binary C style Logical And, start with the first term.
- If $y == 0, the first term is false, so return false/0.
- If $y != 0, the first term is true so evaluate the second term.
- If $x / $y == 0, the second term is false, so return false/0.
- If $x / $y != 0, the second term is true, so return true.
- When && returns true, it returns the return value of the last expression in the chain, hence $x / $y.
Hope that's clear...