Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Error on comment line

by diskcrash (Hermit)
on Jan 30, 2007 at 20:05 UTC ( #597437=perlquestion: print w/replies, xml ) Need Help??
diskcrash has asked for the wisdom of the Perl Monks concerning the following question:

Fine Monks,

Like a good Perl coder I use strict and -w. From time to time I get error messages such as:

Use of uninitialized value in concatenation (.) or string at /task Line 392.

This line 392 is commented out with a leading #. Lines before and after have strings used in assignments or comparisons.

This has happened in several programs and I wondered if there is a generic reason.

TNX! Diskcrash

Replies are listed 'Best First'.
Re: Error on comment line
by perrin (Chancellor) on Jan 30, 2007 at 20:31 UTC
    You must have enabled Perl's secret comment analysis AI mode. With this on, it will tell you if your comments are good. Common warnings include:
    • Vast understatement at line 39
    • Stop treating me like a child! at line 174
    • This comment came from the POD that you copy/pasted it from at line 735
    • No one is going to read this whole thing at line 312
Re: Error on comment line
by gaal (Parson) on Jan 30, 2007 at 20:25 UTC
    What the other monks said. Here's a practical way to find your erroneous line. Put the following just above the comment at line 392 and rerun the program:

    #line 10000

    If the error reappears with the same line number, move the #line marker a little upwards. If the line number jumps to > 10,000, start counting from the marker. Tweak as necessary.

Re: Error on comment line
by liverpole (Monsignor) on Jan 30, 2007 at 20:07 UTC
    Hi diskcrash,

    Often the line that Perl thinks caused the error is only very close to the actual error line (like one line away).

    If you have an example, please post it, and we can provide a higher level of enlightenment!

Re: Error on comment line
by ww (Archbishop) on Jan 30, 2007 at 20:09 UTC
    I believe the "generic" reason is generally agreed to be that "Perl sometimes gets a bit confused" about line numbers.

    However, depending on your editor, using (or foreswearing) word_wrap is likely to mean that what Perl understands to be line 392 is actually somewhere other than the line so-identified by your editor or IDE.

Re: Error on comment line
by ikegami (Pope) on Jan 30, 2007 at 20:59 UTC
    Note that "foo$bar" can issue that warning even though concatenation wasn't used explicitly.
Re: Error on comment line
by ferreira (Chaplain) on Jan 31, 2007 at 09:45 UTC

    Maybe this comment is not a comment indeed. It may be inside a larger quote construct that does interpolation, like

    my $a = " # this is a comment, but not really (with $interpolation) $a = 3 "; print $a
    printf <<PERL, "not"; for (@html) { pretty_print($_) } # a comment is %s always a $comment # subtler because of here-docs PERL

    Any of these would trigger similar warnings, due to the unitialized contents in $interpolation, $a and $comment.

      Being a runtime warning, the line number in the message would be the line number of the start of the statement. In the first snippet, the warning would appear to originate from my $a = ", not the "comment" line.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://597437]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2017-06-23 15:09 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (549 votes). Check out past polls.