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
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 ?
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.
>> 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...
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 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.
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.
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/"
> 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
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
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.