On Mon, Oct 31, 2011 at 04:21:18PM +0200, Meir Guttman wrote:
> Hey Mongers!
> 
> Goggling around, I could not determine whether or not Perl LABELs are
> subject to the usual lexical scoping rules as are "my" declared variables.


Labels are not varriable and not affected by my.  


The "if" statement is
straightforward.  Because BLOCKs are always bounded by curly brackets,
there is never any ambiguity about which "if" an "else" goes with.  If you
use "unless" in place of "if", the sense of the test is reversed. Like
"if", "unless" can be followed by "else". "unless" can even be followed
by one or more "elsif" statements, though you may want to think twice
before using that particular language construct, as everyone reading
your code will have to think at least twice before they can understand
what's going on.

       The "while" statement executes the block as long as the expression
       is true.  The "until" statement executes the block as long as the
       expression is false.  The LABEL is optional, and if present,
       consists of an identifier followed by a colon.  The LABEL
       identifies the loop for the loop control statements "next",
       "last", and "redo".  If the LABEL is omitted, the loop control
       statement refers to the innermost enclosing loop.  This may
       include dynamically looking back your call-stack at run time to
       find the LABEL.  Such desperate behavior triggers a warning if
       you use the "use warnings" pragma or the -w flag.

       If there is a "continue" BLOCK, it is always executed just before
       the conditional is about to be evaluated again.  Thus it can be
       used to increment a loop variable, even when the loop has been
       continued via the "next" statement.

       Extension modules can also hook into the Perl parser to define
       new kinds of compound statement.  These are introduced by a
       keyword which the extension recognises, and the syntax following
       the keyword is defined entirely by the extension.  If you are an
       implementor, see "PL_keyword_plugin" in perlapi for the mechanism.
       If you are using such a module, see the module's documentation
       for details of the syntax that it defines.




> I
> almost always label "for"/"foreach"/"while" etc. blocks so it should be
> clear where will "next"/"last"/"redo" go. And sometimes the natural name for
> the loop is the same, e.g., "EMPLOYEE:".  So I wonder if I can reuse the
> same label if it is clearly in a different scope.
> 
> Simple tests were successful, but I would like to have a more authoritative
> answer. The closest I came to finding any reference to the issue is in
> <http://perldoc.perl.org/perlsyn.html#Goto> "perlsyn" GOTO:
> 
> The goto <http://perldoc.perl.org/functions/goto.html> -EXPR form expects a
> label name, whose scope will be resolved dynamically. This allows for
> computed goto <http://perldoc.perl.org/functions/goto.html> s per FORTRAN,
> but isn't necessarily recommended if you're optimizing for maintainability:
> 
> 1.      goto <http://perldoc.perl.org/functions/goto.html> (("FOO", "BAR",
> "GLARCH")[$i]);
> 
> But although this does suggest  a scope for a label, it does not answer IMHO
> my question beyond doubt.
> 
> Can anybody elucidate?
> 
> Regards,
> Meir
> 
>  
> 

> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl


-- 
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software

So many immigrant groups have swept through our town that Brooklyn, like 
Atlantis, reaches mythological proportions in the mind of the world  - RI Safir 
1998

http://fairuse.nylxs.com  DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

"Yeah - I write Free Software...so SUE ME"

"The tremendous problem we face is that we are becoming sharecroppers to our 
own cultural heritage -- we need the ability to participate in our own society."

"> I'm an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been 
attached at the hip since the 1st dynasty in Ancient Egypt.  I guess you missed 
that one."

© Copyright for the Digital Millennium
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to