Uri Guttman <u...@stemsystems.com> writes: > On 06/24/2013 08:46 AM, lee wrote: >> John Delacour <johndelac...@gmail.com> writes: >>> >>> “Stop if it’s raining, open your umbrella.” >>> >>> Nobody would know what you intend to say. No condition is actually >>> attached to “stop”. >> last if $its_raining; >> >> By your logic, no condition is attached to "last". The problem with >> perl is that it doesn't allow you to open your umbrella. >> >> > > i have been following this thread and i haven't seen a good > explanation to you about what is really going on.
Thank you for your explanation! > first off, last and th if modifier have nothing to do with each > other. Yes --- and you actually call it an "if modifier". I was merely expecting an 'if' to be an 'if' like always. But perl has two different 'if's, the usual one and the modifying one. > last is a just a normal builtin and the if modifier can be > appended to any statement. why you think last behaves differently with > if i cannot fathom. That's not what I'm thinking. The 'last' statement was only an example because I was trying to figure out what exactly it does, particularly when used together with 'if'. > the important point is that last executes immediately and any > expressions after it will not be executed. The 'if modifier' is executed, that is what makes a 'last if ...' particularly confusing. It's also confusing to have two different 'if's. > last and print "foo" ; # will never print foo. That's very irregular, considering that there is last if $condition; # will always execute the code after last > print "foo" and last ; # will always print foo. > > both of those could be appended with an if modifier. and guess what? > they behave the same as before IF the if condition gets met. Yes, and the 'if' behaves differently than 'if'. > otherwise the entire statement is skipped. the if modifier is great > but is best used on short simple statements. complex statements > (multiple parts with and/or/comma, etc) are best done in an if block. Well, I find a simple statement like print "unless\n" unless 0; totally confusing. I have to translate 'unless' into 'if not' first. Then I would, quite naturally, expect unless 0 { print "unless\n"; } to work, but it doesn't compile. It is another irregularity that one time you must use brackets and another time you don't need them. When you try unless 0 print "unless\n"; it doesn't compile, either. Where's the logic in that? > last by itself is simple and goes well with if modifier. > > last if SOME_LOOP_CHECK ; > next unless OTHER_CHECK ; > > those are very common and readable perl statements. It's an inconsistency. > as for the ternary (or conditional) operator, it is designed for its > return value. its precedence and that of other ops works fine if it > just returns one of two expression. when you get into assignment, the > precedence blows up and you need parens. That's a really good point :) > so you can code however you want but when people look at your code > later on they will question it and wonder why you chose the wrong > idioms. this will affect code review, job prospects, and more. there > are reasons both logical and social why some idioms are better than > others. learn the reasons and your code will be better and easier to > read and maintain. That's another good point --- and I like it when my code looks good, no matter whether anyone else ever sees it or not. Besides it being easier to work with, beautiful code is very pleasing. -- "Object-oriented programming languages aren't completely convinced that you should be allowed to do anything with functions." http://www.joelonsoftware.com/items/2006/08/01.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/