On Sun, Jun 23, 2013 at 12:02:38PM +0300, Shlomi Fish wrote: > "last" is not a function (a.k.a "subroutine") - it cannot be. > It is a special statement which is handled in a special way by > the Perl interpreter. "redo" and "next" are not functions > either for a similar reason.
I think we can all agree that last is not a function/subroutine, but at the same time it does behave like one in several ways. :) For example, you can follow it with parenthesis if you want (albeit, there's no good reason to do that). #!/usr/bin/perl use strict; use warnings; while(1) { last(); } __END__ Similarly, you can even wrap it up in a subroutine and it still works as intended (so obviously it understands just how to find the right enclosing block even through subroutine calls). #!/usr/bin/perl use strict; use warnings; while(1) { my_last; } sub my_last { last; } __END__ Perl is just magic. ;) It's just one of those things. It's good to understand that it's special and meant to be a control-flow statement. The perldoc describes it as a "command". Particularly surprising is that a stand-alone block is considered the same "beast" as loops so last will affect that as well! #!/usr/bin/perl use strict; use warnings; do { { last; } print "This is reached!\n"; } while(0); __END__ Personally I'm of the opinion too that unnecessary labels don't really benefit the code any. They're certainly helpful to jump several levels in a clean way. though I wouldn't oppose using a goto for that in languages that lack labelled next/last/continue/break statements. >:) 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