Here's a feature I've often wanted in various languages (perl included), let me know if you think this would be useful.
It's a modification to a foreach loop, such that if the loop condition NEVER happens, the ELSE path is taken. Often I'll find myself with a loop that might not happen, and I have to cover that alternative. Listing items in a list, for example: [% FOREACH Item = List %] Item [% loop.count %] [% Item %] [% ELSE %] No items found [% END %] Currently I have to either put some flag in the loop, or write a test of the contents of List. (If List is an existing arrayref to an empty array, this is more than an IF statement. Not hard, but it obscures the meaning.) I don't know how much work would have to be done in the parser to make this work. I imagine it could be abused for obfuscation: FOREACH ELSIF ELSIF END Plus there are some negotiation issues: Should this hit the ELSE condition if the LAST is used? I'd think not. FOREACH LAST ELSE END Would this mean we'd want some new command to do that? FAIL? Or is that the sort of condition that we would want the user to go back to the "normal" way of doing things? Am I alone in thinking this sort of thing would linguistically improve scripts?
