We don't bite newbies here... much | |
PerlMonks |
Re: use of lastby Eily (Monsignor) |
on Jul 20, 2015 at 08:20 UTC ( [id://1135413]=note: print w/replies, xml ) | Need Help?? |
Actually last will only work on loops. A single block, without any kind of flow control (if, do while, for) counts as a loop that executes only once. So Will work, and you can make it work with your code by doubling the curly brackets:
last will never allow you to exit an if-block, because it is often used in constructs such as: Note that it's always possible to name the while loop to provide the name to last and make it clearer what you are leaving. Edit: completed my last sentence (apparently I forgot what I was saying mid-sentence), and added a condition after the if, so that the code doesn't look so odd. Edit: BTW, I think that karlgoethebier's version is easier to read.
In Section
Seekers of Perl Wisdom
|
|