[ABE.pm] ternary operator

Michael C. Toren mct at toren.net
Fri Jul 22 15:19:24 PDT 2005


On Fri, Jul 22, 2005 at 05:56:04PM -0400, Faber Fedor wrote:
> I thought I could be more succint by saying
> 
> $endYYYYMM ? $tempDate = $endYYYYMM."28" : $tempDate = $YYYY.$MM."28";
> 
> but that always executes the false statment

If you add a few parentheses to the above, this should work just fine:

	$foo ? ($bar = 1) : ($bar = 2);

However, if you factor out the common code, you end up with:

	$bar = $foo ? 1 : 2;

which is a bit more readable, imo.

HTH,
-mct

-- 
perl -e'$u="\4\5\6";sub H{8*($_[1]%79)+($_[0]%8)}sub G{vec$u,H(@_),1}sub S{vec
($n,H(@_),1)=$_[2]}$_=q^{P`clear`;for$iX){PG($iY)?"O":" "forX8);P"\n"}for$iX){
forX8){$c=scalar grep{G@$_}[$i-1Y-1Z-1YZ-1Y+1ZY-1ZY+1Z+1Y-1Z+1YZ+1Y+1];S$iY,G(
$iY)?$c=~/[23]/?1:0:$c==3?1:0}}$u=$n;select$M,$C,$T,.2;redo}^;s/Z/],[\$i/g;s/Y
/,\$_/xg;s/X/(0..7/g;s/P/print+/g;eval' #     Michael C. Toren <mct at toren.net>



More information about the ABE-pm mailing list