Error message line number in subs

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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,...
    3. 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 :-...
    4. 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 ...
    5. 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...
  3. #2

    Default Re: Error message line number in subs

    laszlo <GlgAs@Netscape.net> wrote in comp.lang.perl.misc:
    > 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.
    Line numbers in Perl error messages have never been 100 % accurate. It
    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.
    > 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)
    Short of patching the Perl kernel, there is little you can do. Learn to
    live with Perl's quirks.
    > 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
    Are you sure the first line of your code is what Perl sees as line 1?
    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

  4. #3

    Default 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

  5. #4

    Default Re: Error message line number in subs

    laszlo wrote:
    >
    > 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
    Seeing the error as being on the END line of the "while"
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139