Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Less-than-helpful warnings

by Sandy (Curate)
on Dec 10, 2003 at 23:44 UTC ( [id://313921]=note: print w/replies, xml ) Need Help??


in reply to Less-than-helpful warnings

Ditto with all the rest of the replies, except... some strange behaviour.
Note that if your undefined variable is 1st in the string, no warning message.

The second print statement does not print a warning.
Mmmm....

#!/usr/bin/perl -w my $a = 1; my $b = 2; my $c = 3; my $d = 4; my $e; print "$a $b $c $d $e\n"; print "$e $a $b $c $d\n";
My guess is that it is the concatenation of a 'null' that causes the warning.

"$a $b" is optimized to $a." ".$b according to the message I get when I use the 'use diagnostics' with this code.

Replies are listed 'Best First'.
Re: Re: Less-than-helpful warnings
by ysth (Canon) on Dec 11, 2003 at 03:40 UTC
    The second print gives a warning for me with 5.8.1 and above but not with 5.6.2, so this sounds like a bug that was fixed to me.
Re: Re: Less-than-helpful warnings
by jpfarmer (Pilgrim) on Dec 11, 2003 at 17:46 UTC
    according to the message I get when I use the 'use diagnostics' with this code.

    Since Sprad was looking for better messages "for warnings like these", I think it's worthwhile to emphasize the use diagnostics pragma Sandy mentioned.

    Consider this trivial case:

    #!/usr/bin/perl -w my $a = 1; my $c = 2; print $a + c;

    Without using diagnostics, I get this:

    Unquoted string "c" may clash with future reserved word at test.pl line 5.
    Argument "c" isn't numeric in addition (+) at test.pl line 5.

    However, if I do use it, I get a much more informative error:

    Unquoted string "c" may clash with future reserved word at test.pl line 5 (#1)
    
        (W reserved) You used a bareword that might someday be claimed as a reserved word.
        It's best to put such a word in quotes, or capitalize it somehow, or insert
        an underbar into it.  You might also declare it as a subroutine.
    
    Argument "c" isn't numeric in addition (+) at test.pl line 5 (#2)
    
        (W numeric) The indicated string was fed as an argument to an operator that
        expected a numeric value instead.  If you're fortunate the message
        will identify which operator was so unfortunate.
    

    Sure, in the case I've provided it isn't especially helpful, but it can be useful for tracking down more bizarre errors by giving some suggestions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-19 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found