The other day when I was working on Perl's regexp (?{...}) construct and constraining matches. I came across a strange error message. Before I start in, let me state that I'm fully aware that (?{...}) is considered a "highly experimental" feature, and that I should expect quirks. But that said, here's the background:
The following code will produce a runtime warning:
print rand + 5;The warning will be:
Warning: Use of "rand" without parentheses is ambiguous at mytest.pl line 4 (#1)This is understandable (though it's one case where whitespace does matter, as "print rand +5;" doesn't trigger a warning), and the information returned from 'use diagnostics' pretty much tells the story:
Warning: Use of "rand" without parentheses is ambiguous at mytest.pl l +ine 4 (#1) (S ambiguous) You wrote a unary operator followed by something tha +t looks like a binary operator that could also have been interpreted + as a term or unary operator. For instance, if you know that the rand function has a default argument of 1.0, and you write rand + 5; you may THINK you wrote the same thing as rand() + 5; but in actual fact, you got rand(+5); So put in parentheses to say what you really mean.
Now look at the following snippet, which commits the same faux pax within a (?{ code }) block of a regular expression:
use strict; use warnings; use diagnostics; my $string = "1230000000"; print $string =~ m/123(?{(pos <= length($_)*.5) ? '(?=)':'(?!)'})(??{$ +^R})/ ? "Matched.\n" : "Didn't match.\n"; __OUTPUT__ Warning: Use of "pos" without parentheses is ambiguous at (re_eval 2) +line 1 (#1 ) (S ambiguous) You wrote a unary operator followed by something tha +t looks like a binary operator that could also have been interpreted + as a term or unary operator. For instance, if you know that the rand function has a default argument of 1.0, and you write rand + 5; you may THINK you wrote the same thing as rand() + 5; but in actual fact, you got rand(+5); So put in parentheses to say what you really mean. panic: top_env
Again, the same warning, and the same diagnostic message: no problem. But what's with the "panic: top_env" message? And why doesn't it print out a diagnostic too?
Looking in perldiag I found the following:
(P) An internal error you should never see (trappable).
....
panic: top_env
(P) The compiler attempted to do a goto, or something weird like that.
First, what is this? Second, since I "should never see" this, does the fact that I am seeing it indicate that I should submit a perlbug report?
With similar snippets I've also managed to trigger the following similar error:
panic: restartop (P) Some internal routine requested a goto (or something like it), and + didn't supply the destination.
Though I can't remember how to reproduce the latter, they seem related. I cannot help but think that if I'm seeing these sorts of messages, there is a loose end somewhere in Perl that needs to be tied up. Any voices of agreement or disagreement?
Dave
In reply to "panic: top_env": Is this error resulting from a Perl bug? by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |