Some languages, such as awk script, allow conditional assignments. For example, let's say that you have a list file in the format:
<item name, no spaces> <price as float>
eg.
Grape 4.99 JuicyFruitGum 0.45 Candles 5.99
And you wanted to tax everything over $ 1 ... you could use an awk script:
awk '{a=($2>1.00)?$2*1.06:$2; print a}' prices.data
... which uses conditional assignment to shorten the syntax.
But say that you also wanted to offer $ 1 for all items worth more than $ 20 and $ 2 apiece for more than $ 40. Well, in a language like c, you usually do something like:
if (price > 40.00) { price-=2; price *= 1.06; } else if ( price > 20.00 && price <= 40.00 ) { price--; price *= 1.06; } else if ( price > 1.00 ) { price*=1.06; }
... well, I found that you can clone awk or other scripting languages ββinto a COMPOUND assignment. eg:.
awk '{a=($2>1.00)?($2>20.00)?($2-1)*1.06:($2>40.00)?($2-2)*1.06:$2*1.06:$2; print a}' prices.data
My questions are that
a) is a complex assignment (such as this) universally compatible with scripting languages ββthat support conditional assignment?
b) Is there a non-kludge method for performing multiconventional assignment in an awk script?
To clarify: I am talking exclusively about the abbreviation for assignment (<...>? <...>: <...>; rather than the traditional conditional assignment, which I already know how to make a c-like connection assignment in Awk script. As a side note on why I can use the short form, I think the dignity is obvious - it's short, but like regular expressions, you might want to write a good description of what your obscure syntax does for posterity.