develooper Front page | perl.perl5.porters | Postings from May 2008

Re: Should potentially confusing labels emit a warning?

Thread Previous | Thread Next
From:
Ed Avis
Date:
May 15, 2008 01:27
Subject:
Re: Should potentially confusing labels emit a warning?
Message ID:
loom.20080515T081953-556@post.gmane.org
Aristotle Pagaltzis <pagaltzis <at> gmx.de> writes:

>>     BEGIN: {
>>         # This code gets executed at run time, because the colon
>>         # after BEGIN means it's just a plain old label
>>     }

I think that a warning is a good idea - I can't imagine any false positives, and
you already have evidence that people tend to make this mistake.

Indeed, why just a warning?  Surely using a language keyword as a label should
be disallowed altogether.  At the moment the behaviour is a bit bizarre:

    print: { say 'hello' }
    goto print;

fails with 'Can't find label 1', as if this were a computed goto using the
return value of evaluating print, but on the other hand if you try to make such
a computed goto using your own function:

    sub f { return 1 }
    goto f;

you get 'Can't find label f', showing that it's treated as a literal word and
not evaluated.

IMHO, this semantic muddle is best resolved by forbidding builtin keywords as
labels.

-- 
Ed Avis <eda@waniasset.com>



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