On Thu, 23 Sep 2010, IOhannes m zmoelnig wrote:
yes, but i believe this is because you are very used to C-like languages, so you assume that expr's if looks like: "if <condition>, <then>, <else>". you have been trained on that, probably since high school (and eventually used it before) [*]. if you had been fed on perl, you might find other things more easily to read.
Perl also has a conditional-statement almost like C's. There are some differences. Its syntax is if (a) {b} else {c} instead of if (a) b; else c; because Perl has no separate concept of compound statement.
And then also Perl has more different implicit conversions to bool than C has.
The if-statement is remarkably uniform across different languages, in a way that the for-loop and the switch-statement aren't.
The biggest difference you will see, is that some if-statements are actually if-expressions instead. This is the case with if(,,) in the [expr] class. This is also the case with a?b:c in C language. It's the case with if/then/else/end in Ruby and the if {} {} {} in Tcl.
Perl is somewhat in-between because although you can't assign the result of an if-statement to a variable, you can return it from a function, but that's because Perl uses the value of the last executed statement as the default return value.
| Mathieu Bouchard ------------------------------ Villeray, Montréal, QC