On Tue, 5 Feb 2002, John Mooney wrote: > Actually, it is not an incorrect way I believe, so much as he is using > slightly incorrect syntax. From the Nutshell ...
I really meant 'incorrect' in its usage, not the syntax -- he was using it in a void context. > ... I think the key is that he was not using a token that resulted in an > explicit evaluation, returning & capturing a result. By wrapping the 2nd > and 3rd tokens of the ternary clause in parens, this result can be > acheived. > > Here's an example I use often in CGIs to accomplish background-color > swapping in HTML table rows - achieiving an old computer-paper, > green/white effect: > > local $swapper = -1; # globals > local $bgcolor = ''; > > sub swapBGcolor { > (($swapper *= -1) > 0 ) ? ($bgcolor="#FFFFFF") : ($bgcolor="#F5DCC7"); > } That can be dangerous, IMHO, modifying globals like that (I know it would cause some problems in mod_perl!) I would instead code it so that the little subroutine returns the value you need: $bgcolor = swapBGcolor(); sub swapBGcolor { return ($swapper *= -1) > 0 ? '#FFFFFF' : '#F5DCC7' } That's just more a matter of style -- I get the willies when subroutines modify global values invisibly. -- Brett http://www.chapelperilous.net/ ------------------------------------------------------------------------ The English have no respect for their language, and will not teach their children to speak it. -- G. B. Shaw -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]