DCPM: Little syntax query

Neil Williams linux at codehelp.co.uk
Wed Dec 3 13:52:28 CST 2003


I'm confused over ? : conditionals
If I have this code:
if($asyncz == 0) {$port = $list[5];}
else{ $port = $list[3];}

Why doesn't this work instead?
$asyncz ? $port = $list[5] : $port = $list[3];

Also, is ? : limited to if then else - if there is no else, do I have to use 
if() {} anyway?

$ perl -e '$asyncz = 0 ; $asyncz ? $port = 5 : $port = 3; print $port;'
$ perl -e '$asyncz = 1; $asyncz ? $port = 5 : $port = 3; print $port;''

Both give 3.

My otherwise excellent documentation doesn't give an example.

-- 

Neil Williams
=============
http://www.codehelp.co.uk/
http://www.dclug.org.uk/
http://www.isbn.org.uk/
http://sourceforge.net/projects/isbnsearch/

http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://mail.pm.org/archives/devoncornwall-pm/attachments/20031203/8a306545/attachment.bin


More information about the Devoncornwall-pm mailing list