DCPM: Little syntax query

Simon Waters simon at wretched.demon.co.uk
Wed Dec 3 15:16:11 CST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 03 December 2003 7:52 pm, Neil Williams wrote:
> perl -e '$asyncz = 1; $asyncz ? $port = 5 : $port = 3; print $port;

I think you want.....

perl -e ' $asyncz=1 ; $port = $asyncz ? 5 : 3 ; print $port,"\n";'

Ah "man perlop" covers your very example - RTFM ;)

$asyncz ? $port = 5 : $port = 3; 

becomes either ($port = 5) = 3;
		or      $port = 3;

Ternary operator would be high on my list of things not to allow if I were 
writing computer language style guides - I can say this as I learnt Fortran. 
Fortran didn't have many features as a language and we still use to condemn 
this one!!!!

Consider the most readable solution, if/else is usually quite readable ;) 
-----BEGIN PGP SIGNATURE-----
Comment: Encryption...is a powerful defensive weapon for free people.

iD8DBQE/zlKbGFXfHI9FVgYRAn2dAKCb6vXjjfI2azAIijEBqEFY+BLscQCffqAh
0WdQuLioCwvxLjQ0D8cDz/I=
=n1Zc
-----END PGP SIGNATURE-----




More information about the Devoncornwall-pm mailing list