Ask a Question related to PERL Miscellaneous, Design and Development.
-
laszlo #1
Error message line number in subs
I have an interactive perl cgi programlet, which allows some graphics
for interactively typed and executed perl programs:
[url]http://lzkiss.netfirms.com/cgi-bin/igperl/igp.pl?name=test[/url]
Until I used perl 5.6 the programlet below didn't gave any error
message for the "while (true) {" statement. In my localhost I updated
to ActiveState 5.8.0 version, and the bareword true causes an error in
while. However the associated line number is not the real line number,
but the last line of the sub, so line 9 instead of the actual line
number of the error. If I modify the program to e.g. "while (true ==
1) " there is an error with the proper line number. Apparently the
program precompiles the condition in the sub and reports the error as
it would be at the last line of the sub.
Is there anything I can do to get the correct error number (I list $@
after calling eval for the programlet; the head with use statements is
called outside the eval function)
use warnings;
use strict "subs";
use strict "refs";
$a = 1;
sub alma {
while (true) {
$a = 2;
}
}
true;
Bareword "true" not allowed while "strict subs" in use in test.func
line 9
(You don't see this error on the above webpage because the public
server is using 5.6)
laszlo Guest
-
Return Line Number of text in a textfield?
Can the line numbers of the text containing a special character be retrieved? e.g. text in a textfield: #line 1 line 2 line 3 #line 4 line... -
Inserting Line Number
I would like to insert line numbers for all the files in a directory. So if a directory contains files like foo.c, foo.c1, foo.c2, foo.c3, foo.c4,... -
A (probable) error in perltoot ( perl5/5.8.0/pod/perltoot.pod, line number 756 )
Dear Perl Programmers, I tried out the code given in :- http://www.perldoc.com/perl5.8.0/pod/perltoot.html#Aggregation The following line :-... -
Get number of line with error
Hi all. I want ask you it exist some way how to get number of line in script producing error. for example: .... .... 100 ... -
Error line number
Hi Newsgroup, A very short question: If have a try/catch structure. In the catch part I would like to get the line number where the exception... -
Anno Siegel #2
Re: Error message line number in subs
laszlo <GlgAs@Netscape.net> wrote in comp.lang.perl.misc:
Line numbers in Perl error messages have never been 100 % accurate. It> I have an interactive perl cgi programlet, which allows some graphics
> for interactively typed and executed perl programs:
>
> [url]http://lzkiss.netfirms.com/cgi-bin/igperl/igp.pl?name=test[/url]
>
> Until I used perl 5.6 the programlet below didn't gave any error
> message for the "while (true) {" statement. In my localhost I updated
> to ActiveState 5.8.0 version, and the bareword true causes an error in
> while. However the associated line number is not the real line number,
> but the last line of the sub, so line 9 instead of the actual line
> number of the error. If I modify the program to e.g. "while (true ==
> 1) " there is an error with the proper line number. Apparently the
> program precompiles the condition in the sub and reports the error as
> it would be at the last line of the sub.
was worse in Perl 5.5 than in 5.6 and got still better in 5.8, but
occasionally the line number is off. Usually this happens with multi-
line statements, where the reported line number is the first line of the
statement while the error happened a few lines down in the same statement.
Looking at how complicated the lexing/parsing process in Perl is, it's
amazing it even has an idea where the stuff it's compiling comes from.
Short of patching the Perl kernel, there is little you can do. Learn to> Is there anything I can do to get the correct error number (I list $@
> after calling eval for the programlet; the head with use statements is
> called outside the eval function)
live with Perl's quirks.
Are you sure the first line of your code is what Perl sees as line 1?> use warnings;
> use strict "subs";
> use strict "refs";
> $a = 1;
> sub alma {
> while (true) {
> $a = 2;
> }
> }
>
> true;
>
> Bareword "true" not allowed while "strict subs" in use in test.func
> line 9
I have never seen Perl claim the closing bracket of a sub as an error.
What's more interesting is that apparently some Perls accept a bareword
as a while-condition. 5.8.0 does it too, apparently 5.6 doesn't. This
is a minor bug that has better expectations of being fixed.
FWIW, 5.8.0 reports all errors with the correct line number. As mentioned,
it doesn't report "while ( true ) {".
Anno
Anno Siegel Guest
-
Matt Churchyard #3
Re: Error message line number in subs
'true' is not a keyword in perl and is being interpreted as a bareword
IMHO it is a bad idea to use barewords anywhere (the program wont run at all
under 'use strict)',
and I would replace both instances of 'true' with 1 or define true as a
constant - ie
use constant true => 1;
--
Matt
"laszlo" <GlgAs@Netscape.net> wrote in message
news:945e4584.0308290520.6edc04ff@posting.google.c om...> I have an interactive perl cgi programlet, which allows some graphics
> for interactively typed and executed perl programs:
>
> [url]http://lzkiss.netfirms.com/cgi-bin/igperl/igp.pl?name=test[/url]
>
> Until I used perl 5.6 the programlet below didn't gave any error
> message for the "while (true) {" statement. In my localhost I updated
> to ActiveState 5.8.0 version, and the bareword true causes an error in
> while. However the associated line number is not the real line number,
> but the last line of the sub, so line 9 instead of the actual line
> number of the error. If I modify the program to e.g. "while (true ==
> 1) " there is an error with the proper line number. Apparently the
> program precompiles the condition in the sub and reports the error as
> it would be at the last line of the sub.
>
> Is there anything I can do to get the correct error number (I list $@
> after calling eval for the programlet; the head with use statements is
> called outside the eval function)
>
> use warnings;
> use strict "subs";
> use strict "refs";
> $a = 1;
> sub alma {
> while (true) {
> $a = 2;
> }
> }
>
> true;
>
> Bareword "true" not allowed while "strict subs" in use in test.func
> line 9
>
>
> (You don't see this error on the above webpage because the public
> server is using 5.6)
Matt Churchyard Guest
-
Michael P. Broida #4
Re: Error message line number in subs
laszlo wrote:
Seeing the error as being on the END line of the "while">
> use warnings;
> use strict "subs";
> use strict "refs";
> $a = 1;
> sub alma {
> while (true) {
> $a = 2;
> }
> }
>
> true;
>
> Bareword "true" not allowed while "strict subs" in use in test.func
> line 9
statement makes SOME sense to me, based on my experience
with other languages.
In all the C or C++ compilers I've seen the test for the
"while" statement is actually done at the END of the loop.
Yes, the test has to be PERFORMED before the first pass, so a
jump to the end of the loop is placed just before the loop,
thus causing the test to be done before the code inside the
loop is executed. (A "do-while" would omit the initial
"jump".)
Sounds confusing, so here's a (hopefully helpful) diagram
of what I'm describing: (sorry if it displays oddly for you)
C/C++ code compiled implementation
--------------- -----------------------
<none> jump to ZZZ
while (CCC) AAA:
{
<dosomething> <dosomething>
} ZZZ: if CCC, go to AAA
That's the way I've always seen it in the output of the C or
C++ compiler (and other languages with similar loop structures).
Not pretty, but the compiler writers must figure it gains
them something to do it that way.
So, when an error occurs in the evaluation of "CCC", the
error is reported as being in the line at the END of the
loop because that's where the code really resides.
I don't know if Perl code compiles the same way, but it
could be an explanation for what you're seeing.
Mike
Michael P. Broida Guest



Reply With Quote

