develooper Front page | perl.perl5.porters | Postings from July 2018

Re: [perl #133249] Duplicate label does not produce a syntax error.

Thread Previous | Thread Next
From:
demerphq
Date:
July 4, 2018 14:21
Subject:
Re: [perl #133249] Duplicate label does not produce a syntax error.
Message ID:
CANgJU+UvsRiEEOJPtU=CRY5mKbULR6wOu_nsZJ8Jr=hWEJ7HCg@mail.gmail.com
On Wed, 20 Jun 2018, 03:46 Dave Mitchell, <davem@iabyn.com> wrote:

> On Tue, Jun 19, 2018 at 09:45:58AM +0100, Dave Mitchell wrote:
> > The behaviour of 'goto LABEL' is arcane, but the code above is legal and
> > unambiggous, in that at run time, perl searches out from the current
> > statement for a matching label, initially in the current scope, anf if
> > not found, in outer scopes. So it operates a 'closest match' policy.
>
> Thinking further, a more ambiguous case is would be
>
>     {
>         FOO:
>         ...
>         goto FOO;
>         ...
>         FOO:
>         ...
>     }
>
> I think the goto docs should explain better how it searches for labels.
>
> Here's an example of where having the same label twice in the same scope
> could be regarded as legitimate:
>
>     {
>         FOO: for (...) {
>             for (...) { ...;  last FOO if ...; }
>         }
>
>         FOO: for (...) {
>             for (...) { ...;  last FOO if ...; }
>         }
>


Loop labels and statement labels are distinct afaiui, you can't goto a loop
label.

Yves



>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About