KW.pm Only the Lonely #5

diagnostics

        % perl -e 'use diagnostics; $a, $b = <STDIN>;'
        Useless use of a variable in void context at -e line 1 (#1)
            (W void) You did something without a side effect in a context that does
            nothing with the return value, such as a statement that doesn't return a
            value from a block, or the left side of a scalar comma operator.  Very
            often this points not to stupidity on your part, but a failure of Perl
            to parse your program the way you thought it would.  For example, you'd
            get this if you mixed up your C precedence with Python precedence and
            said
                $one, $two = 1, 2;
            when you meant to say
                ($one, $two) = (1, 2);
            Another common error is to use ordinary parentheses to construct a list
            reference when you should be using square or curly brackets, for
            example, if you say
                $array = (1,2);
            when you should have said
                $array = [1,2];
            The square brackets explicitly turn a list value into a scalar value,
            while parentheses do not.  So when a parenthesized list is evaluated in
            a scalar context, the comma is treated like C's comma operator, which
            throws away the left argument, which is not what you want.  See
            perlref for more on this.
        Name "main::a" used only once: possible typo at -e line 1 (#2)
            (W once) Typographical errors often show up as unique variable names.
            If you had a good reason for having a unique name, then just mention it
            again somehow to suppress the message.  The our declaration is
            provided for this purpose.
        Name "main::b" used only once: possible typo at -e line 1 (#2)

<< Previous | Index | Next >> Copyright © 2005 Daniel Allen