On Mon, Jun 24, 2013 at 10:20:36AM +0200, lee wrote: > It's logical and expected because an 'if' statement goes like > 'if(condition) { is_true; } else { is_not_true;}'. > > Put a 'last' in front of the 'if' and the 'if' suddenly goes > like 'if(condition_is_true) last;' and no more. > > Flipping things around and breaking stuff like this is > illogical and unexpected. The 'if' should still go like > 'if(condition) { is_true; } else { is_not_true;}', the only > difference being that the prefixed 'last' is also executed when > the condition is true and not when the condition is not true. > > When you think of a natural language like English, prefixing a > word with "not" doesn't change the meaning of the word that > follows it, *and particularly it does not change the way how > the word is being used in the language*. Prefixing a "not" > only changes the meaning of the /sentence/, like "It is raining > now and we need to close the windows." vs. "It is not raining > now and we do not need to close the windows.". > > What perl does is like forbidding to use any more words after > "raining" and "need" for instances where "raining" or "need" is > prefixed with "not". That's just a very silly thing to do > because it creates a different word (which is written exactly > the same) the usage of which is different from another word > (which is written exactly the same). > > Usually, words that have a different meaning and/or are being > used in a different way in a language aren't the same and are > written differently. Perl uses different words, but written > exactly the same, with different meanings, and they have > different meanings because they are used differently within the > language (which is what makes them different words). That leads > to unexpected behaviour.
I think that you are just misunderstanding what is happening here. `perldoc perlsyn' explains it. These are actually two different things. The compound if-statement, which is typical of other languages, and the if-style "statement modifier". The syntax of the statement modifier is: STATEMENT if EXPR; Where STATEMENT is a single statement (what that statement is doesn't really matter, though the documentation does say "simple" so perhaps there is a limit). For example: last if condition(); It is basically just syntactic sugar to get rid of some braces. It is limited to a SINGLE modifer though so you can't chain them (i.e., ... if ... if ... if ...). It's meant to make code easier to read. Using it for complex statements or complex conditions will likely reduce the readability. In that case, using the plain old if-statement makes better sense. The syntax for that is: if(EXPR) BLOCK Where BLOCK is enclosed with braces. So sticking with our previous example you could express that as: if(condition()) { last; } So your attempts to add a last before the if-statement above are futile. You are combining two different language constructs and they are not compatible. And it's a good thing because I find that hypothetical syntax quite difficult to read. Using English terms, what you're attempting to say is more like: "Stop here if we've iterated thrice write 'if' tracing message." Obviously that doesn't make sense. It needs more language constructs to separate the ideas. For example, perhaps a word like "and". While it might have been possible to support such complexities in a language like Perl, and indeed Perl probably goes further than most languages in this regard, apparently it was decided not to go that far in this case. Regards, -- Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org> Castopulence Software <https://www.castopulence.org/> Blog <http://www.bamccaig.com/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
signature.asc
Description: Digital signature