in reply to Re^3: expression which does nothing
in thread expression which does nothing

It's possible to avoid the warning by using 1 (or 0) instead of 42.
>perl -w -e 42 Useless use of a constant in void context at -e line 1. >perl -w -e 1

It's a special case to allow 1 while ...;.

Replies are listed 'Best First'.
Re^5: expression which does nothing
by bart (Canon) on Dec 27, 2006 at 11:27 UTC
    Not just that. It's also to allow the bare 1; at the end of modules to make it end in a true value, without a complaint under perl -c Foo.pm.

    Note that no true value at the end of a module, whatever you choose, causes a complaint under normal cicrumstances, actually because a module is loaded in scalar context.

    As a test: I saved this little module as "Temp.pm" in the current directory:

    # Temp.pm package Temp; printf "Context = %s\n", defined wantarray ? 0+wantarray : 'undef'; # true value, but may cause warning: "nothing";
    This command line makes it work without warning:
    perl -lib=. -MTemp -we1
    Result:
    Context = 0
    

    But with perl -wc, you do get a warning:

    perl -wc Temp.pm
    Useless use of a constant in void context at Temp.pm line 3.
    Temp.pm syntax OK
    

    Replace the string "nothing" with 1, and you're fine:

    Temp.pm syntax OK