Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Keyword" labels now forbidden (was [perl.git] branch blead, updated. GitLive-blead-1705-gf71d615)

0 views
Skip to first unread message

Jerry D. Hedden

unread,
Jul 29, 2009, 3:41:02 PM7/29/09
to Perl5 Porters
> In perl.git, the branch blead has been updated
>
> <http://perl5.git.perl.org/perl.git/commitdiff/f71d6157c7933c0d3df645f0411d97d7e2b66b2f?hp=0409250f9c9eac87ff80d18e21856800e91763b5>
>
> - Log -----------------------------------------------------------------
> commit f71d6157c7933c0d3df645f0411d97d7e2b66b2f
> Author: Rafael Garcia-Suarez <rgarci...@gmail.com>
> Date:   Tue Jul 28 09:47:24 2009 +0200
>
>    Forbid labels with keyword names

Interesting. This "broke" one of my CPAN modules. Wonder how many
others it will affect?

David Nicol

unread,
Jul 30, 2009, 1:53:28 AM7/30/09
to Jerry D. Hedden, Perl5 Porters
>>    Forbid labels with keyword names
>
> Interesting.  This "broke" one of my CPAN modules.  Wonder how many
> others it will affect?


Why? I've always considered the fact that you can generally use
keywords as other things in Perl to be a good thing.

$ perl -le 'goto: $x++ > 3 and die 1; print $x; goto goto'
1
goto must have label at -e line 1.

$ perl -le 'goto: $x++ > 3 and die 1; print $x; goto "goto"'
1
2
3
4
1 at -e line 1.

it's already a synbtax error when it makes no sense. What's the harm?

--
"It wasn't worth it." -- Harry Patch

Rafael Garcia-Suarez

unread,
Jul 30, 2009, 2:18:25 AM7/30/09
to Jerry D. Hedden, Perl5 Porters
2009/7/29 Jerry D. Hedden <jdhe...@cpan.org>:

I guess that only demonstrates that one can never underestimate the
importance of backwards compatibility. I would never have guessed I
had such a report that fast.

What was the code you used ?

Rafael Garcia-Suarez

unread,
Jul 30, 2009, 2:19:44 AM7/30/09
to David Nicol, Jerry D. Hedden, Perl5 Porters
2009/7/30 David Nicol <david...@gmail.com>:

>>>    Forbid labels with keyword names
>>
>> Interesting.  This "broke" one of my CPAN modules.  Wonder how many
>> others it will affect?
>
>
> Why? I've always considered the fact that you can generally use
> keywords as other things in Perl to be a good thing.
>
> $ perl -le 'goto: $x++ > 3 and die 1; print $x; goto goto'
> 1
> goto must have label at -e line 1.

This error is about the second goto.

> $ perl -le 'goto: $x++ > 3 and die 1; print $x; goto "goto"'
> 1
> 2
> 3
> 4
> 1 at -e line 1.
>
> it's already a synbtax error when it makes no sense.  What's the harm?

No it's not :

$ perl -e 'goto print'
Can't find label 1 at -e line 1.

David Nicol

unread,
Jul 30, 2009, 3:22:17 AM7/30/09
to Perl5 Porters
On Thu, Jul 30, 2009 at 1:19 AM, Rafael
Garcia-Suarez<rgarci...@gmail.com> wrote:
> 2009/7/30 David Nicol <david...@gmail.com>:

>> it's already a synbtax error when it makes no sense.  What's the harm?
>
> No it's not :
>
> $ perl -e 'goto print'
> Can't find label 1 at -e line 1.

$ perl -le '1: $x++ > 3 and die 1; goto print $x'
syntax error at -e line 1, near "1:"
Execution of -e aborted due to compilation errors.

is there a way to create "1" as a label? perldoc perlsyn says labels
"consist of an identifer followed by a colon" but the word
"identifier" does not appear again in that document.

Allowing numeric labels would make Perl more friendly to FORTRAN programmers...

Rafael Garcia-Suarez

unread,
Jul 30, 2009, 3:44:08 AM7/30/09
to David Nicol, Perl5 Porters
2009/7/30 David Nicol <david...@gmail.com>:

Or BASIC.

At best I could write a source filter for that. Colon-less numeric
labels at the beginning of lines. And allow uppercase GOTO.

10 say "this is perl, sort of\n";
20 GOTO 10;

Jerry D. Hedden

unread,
Jul 30, 2009, 10:36:15 AM7/30/09
to Rafael Garcia-Suarez, Perl5 Porters
> In perl.git, the branch blead has been updated
>
> <http://perl5.git.perl.org/perl.git/commitdiff/f71d6157c7933c0d3df645f0411d97d7e2b66b2f?hp=0409250f9c9eac87ff80d18e21856800e91763b5>
>
> - Log -----------------------------------------------------------------
> commit f71d6157c7933c0d3df645f0411d97d7e2b66b2f
> Author: Rafael Garcia-Suarez <rgarci...@gmail.com>
> Date:   Tue Jul 28 09:47:24 2009 +0200
>
>    Forbid labels with keyword names

Jerry D. Hedden wrote:
>> Interesting.  This "broke" one of my CPAN modules.  Wonder how many
>> others it will affect?

Rafael Garcia-Suarez wrote:
> I guess that only demonstrates that one can never underestimate the
> importance of backwards compatibility. I would never have guessed I
> had such a report that fast.
>
> What was the code you used ?

The construct was something like this:

# Check on what we've found
CHECK:
foreach my $key (keys(%{$spec})) {
my $spec_item = $$spec{$key};
# No specs to check
if (ref($spec_item) ne 'HASH') {
# The specifier entry was just 'key => regex'. If 'key' is not in
# the args, the we need to remove the 'undef' entry in the found
# args hash.
if (! defined($found{$key})) {
delete($found{$key});
}
next CHECK;
}

... and more similar check ...
}

I didn't think of the label as a keyword. I changed it to
CHECKIT to fix the problem.

I don't have a problem with the change itself. I think it's
a good idea. However, the error message you get doesn't
tell you what you did wrong! Consider:

#!/usr/bin/perl

use strict;
use warnings;

CHECK:
foreach (1..3) {
if ($_ == 2) {
next CHECK;
}
}

# EOF

When run, this produces:

syntax error at label.pl line 7, near ":
foreach "
Execution of label.pl aborted due to compilation errors.

It was only because I had just seen this change to blead
that I understood what the errors I was getting were related
to. Otherwise, I would have been scratching my head, and
probably asking for help on perl5-porters.

How about an error message that tells what the problem
really is:

Can't use keyword as a label.

Otherwise, it may become a problem when this change hits the
streets.

Jerry D. Hedden

unread,
Jul 30, 2009, 1:13:18 PM7/30/09
to demerphq, Rafael Garcia-Suarez, Perl5 Porters
Yves wrote:
> I suspect that you wont be the only one who get nailed by this. I
> suspect that INIT/CHECK are both likely  to be common as labels (in
> sofar as labels go).

Precisely why I wrote about it - just to give people a heads-up.
However, the error message needs to be changed to say that using
a keyword as a label is not allowed.

Demerphq

unread,
Jul 30, 2009, 1:01:45 PM7/30/09
to Jerry D. Hedden, Rafael Garcia-Suarez, Perl5 Porters
2009/7/30 Jerry D. Hedden <jdhe...@cpan.org>:

I suspect that you wont be the only one who get nailed by this. I


suspect that INIT/CHECK are both likely to be common as labels (in
sofar as labels go).

Yves


--
perl -Mre=debug -e "/just|another|perl|hacker/"

David E. Wheeler

unread,
Jul 30, 2009, 2:53:37 PM7/30/09
to Chip Salzenberg, Rafael Garcia-Suarez, Jerry D. Hedden, Perl5 Porters
On Jul 30, 2009, at 10:27 AM, Chip Salzenberg wrote:

> First, how about if we disallow only the BEGIN-family of keywords as
> labels?
> Considering the original bug report those are the ones that can cause
> trouble. Writing "for: {}" is weird but why should we stop you,
> really?

I think just disallowing the uppercase keywords would be sufficient.

> Second, how about if any limitations on labels is only if they're to
> blocks?
> There's no possible confusion about the meaning of the label in:
>
> sub foo () {
> CHECK: for (@a) { ... }
> }
>
> so I don't think we need to forbid it.

Yeah, but then it's inconsistent. Sometimes you can use CHECK for a
label and sometimes you can't?

Best,

David

Nicholas Clark

unread,
Jul 30, 2009, 2:57:48 PM7/30/09
to David E. Wheeler, Chip Salzenberg, Rafael Garcia-Suarez, Jerry D. Hedden, Perl5 Porters
On Thu, Jul 30, 2009 at 11:53:37AM -0700, David E. Wheeler wrote:
> On Jul 30, 2009, at 10:27 AM, Chip Salzenberg wrote:
>
> >First, how about if we disallow only the BEGIN-family of keywords as
> >labels?
> >Considering the original bug report those are the ones that can cause
> >trouble. Writing "for: {}" is weird but why should we stop you,
> >really?
>
> I think just disallowing the uppercase keywords would be sufficient.

Except that the problem is the keywords that are functions:

$ perl -e 'print: goto print'


Can't find label 1 at -e line 1.

Nicholas Clark

Rafael Garcia-Suarez

unread,
Jul 30, 2009, 5:22:48 PM7/30/09
to Chip Salzenberg, David E. Wheeler, Jerry D. Hedden, Perl5 Porters
2009/7/30 Chip Salzenberg <ch...@pobox.com>:
> Darn.  Looks like the already-committed complete ban on keyword labels is
> the sanest option.  Fortunately we do have C<use VERSION> to limit any
> collateral damage from new keywords.

Yes, that's what seemed to me too.

I've now checked in an error message improvement as suggested by Jerry.

$ bleadperl -Esay:
Can't use keyword 'say' as a label at -e line 1.

You will note that "bleadperl -esay:" doesn't produce an error. Only
current keywords are checked.

0 new messages