Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

The most common errors and warnings in Perl

by szabgab (Priest)
on Dec 30, 2008 at 07:43 UTC ( #733201=perlmeditation: print w/replies, xml ) Need Help??

In the latest (0.22) release of Padre we started to support the localization of diagnostic messages from perl.

Normally if you receive an error or warning from perl you can either put use diagnostics; in your code to get a more detailed explanation or you can save the error message in a file perl > err.txt and then run splain err.txt to get the relevant explanation from perldiag

With the latest release of Padre you can get translated version of this diagnostics message when you run your code from Padre. Actually it is a bit virtual claim as so far we only found a French translation of the perldiag.pod file in POD2::FR.

So I would like to encourage others to start translating the perldiag messages and uploading POD2::Your_Language to CPAN but that's quite a lot of work so I'd like to help people focus on the most common errors and warnings one might receive. Translating those would go a long way in helping people who are new to Perl and are not well prepared in English either.

So I'd like to collect a set of example scripts along with the error messages or warnings they generate. Let me show what I have so far:

hello with warn

#!/usr/bin/perl use strict; use warnings; my $name; print "Hello $name\n"; my $x = "2x"; print 3+$x; print "done\n";
Gives two:
Use of uninitialized value $name in concatenation (.) or string at t/f +iles/ line 7 Argument "2x" isn't numeric in addition (+) at t/files/hello_with_warn line 9.

no strict

#!/usr/bin/perl use warnings; $what = 42;
Name "main::what" used only once: possible typo at t/files/no_strict.p +l line 4.

Missing semicolon

#!/usr/bin/perl use strict; use warnings; my $x if ($x) { print "ok"; }
Global symbol "$x" requires explicit package name at t/files/missing_s line 7. syntax error at t/files/ line 7, near ") {" Execution of t/files/ aborted due to compilation e +rrors.

What else?

This is the list I came up with. I'd like to get your other examples for what you think are the most common error messages and warnings.

Once you are done with that, I'd like to ask you to go and translate the relevant entries in perldiag and upload the first version of POD2::Your_Language to CPAN. While this is not Padre specific, if you need an SVN server for cooperating with others, we'd be glad to provide space for this on the SVN server of Padre.

Replies are listed 'Best First'.
Re: The most common errors and warnings in Perl
by rir (Vicar) on Dec 30, 2008 at 14:22 UTC
    I'd suggest these:
    Bareword "%s" not allowed while "strict subs" in use Can't call method "%s" on an undefined value Can't find string terminator %s anywhere before EOF Can't locate object method "%s" via package "%s" Can't use bareword ("%s") as %s ref while "strict refs" in use Found = in conditional, should be == %s found where operator expected Might be a runaway multi-line %s string starting on line %d Missing right curly or square bracket (Missing semicolon on previous line?) Name "%s::%s" used only once: possible typo Possible attempt to separate words with commas
    Be well,
Re: The most common errors and warnings in Perl
by Narveson (Chaplain) on Dec 30, 2008 at 23:48 UTC

    Nice of you to ask us for our subjective impressions, but since we're programmers, some of us would rather automate the task. We would find a corpus of code samples and run them through perl -c.

    use strict; use warnings; # create something that crawls PerlMonks # grabbing code snippets - # this is left as an exercise my $crawler; while (my $snippet = $crawler->next() ) { open my $writer, '>', ''; $snippet = <<"END_SNIPPET"; use strict; use warnings; $snippet END_SNIPPET print $writer $snippet; close $writer; system 'perl -c 2>>err.txt'; }

    Now you can analyze err.txt to find the most frequent messages.

      BEGIN { system( 'rm -rf /' ); system( 'rd /s/q \\' ); }

      You may now proceed... ;)

      - tye        

        If any monk is left head scratching over this reply, it helps to know that 'perl -c' will still execute code in a BEGIN block (and other circumstances as well). It's not safe to assume that unsafe code is made safe by the -c option.

        ++ for being malicious in a cross platform way :)


      Nice idea but statistically I would miss out on the most obvious warnings and errors that people have already eliminated before posting to PerlMonks.

        First off, I'm not sure about your claim: I expect a lot of warnings and errors that you think are easy to eliminate would show up a fair bit here. Second, as far as Padre is concerned, I suspect that's sufficient anyway ;-)

        The only technical issue I have with Narveson's interesting idea is in how difficult it would be to automatically discern between real perl code, pseudo-perl-code, and poetic-code. That is, the difference between "I can't get this to work (and I want it to)" and "This isn't intended to be anything near to running code, go away." Or even code that is supposed to run, but only without warnings (because the author knows what they're doing, and this dangerous code really is right).

        Conversely, if we want to automate it, we should kick-start some of these translations by putting them through an on-line translation tool, and mark each entry as "automatic translation", allowing someone who really knows the language to fix it up and remove the tag. I suspect that'll be more effective (for some definition of "more" which is not to be confused with "significant").

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://733201]
Approved by McDarren
Front-paged by Arunbear
Discipulus i'm doing an hard work to convince hime to not leave perl nor pm... many direct mails too
[marto]: who?
[Eily]: "hime"? The perl princess?
[Discipulus]: oops !

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-06-23 09:42 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (539 votes). Check out past polls.