John W. Krahn wrote:
Zembower, Kevin wrote:
When I execute this line:

$type eq "unknown" ? $type="human" : $type="both";

$type is always "both".

PRECEDENCE!  ?: has higher precedence than =

You want to do it like this:

$type = $type eq 'unknown' ? 'human' : 'both';

Your code parses as:

(  $type eq "unknown"   ?   $type="human"   :   $type  ) = "both";

and so is executed either as

  ($type = "human") = "both";

or

  ($type) = "both";


and while the first is a little strange it is valid Perl, and causes
first 'human' and then 'both' to be assigned to $type. Both cases
therefore have the same final result.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to