mje has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code running on Strawberry perl 32 bit 5.14.2 and it gives the error shown in the titel. It is down to the use open line but I don't understand why.

use open ':std', ':encoding(utf8)'; use Test::More; my $has_test_nowarnings = 1; eval "require Test::NoWarnings"; $has_test_nowarnings = undef if $@; done_testing();

The full error is Useless use of a constant (ict) in void context at I:/strawberry-perl-5.14.2.1-3 2bit-portable/perl/vendor/lib/Test/NoWarnings.pm line 3. I don't get that error with 64 bit strawberry perl. The line 3 referred to is "use strict;".

Replies are listed 'Best First'.
Re: Useless use of a constant (ict) in void context
by ikegami (Patriarch) on Nov 15, 2013 at 18:51 UTC

    Convert the line endings of Test/NoWarnings.pm from LF to CRLF.


    Perl tries to seek back (for reasons I can't remember, perhaps BOM detection), but gets the position wrong because the line ending are different than expected. As a result, Perl ends up thinking the file being executed contains

    ict; use warnings; use Carp (); ...
    or, after your edit,
    rnings; use Carp (); ...
    .
Re: Useless use of a constant (ict) in void context
by tobyink (Canon) on Nov 15, 2013 at 13:58 UTC

    There's possibly something wrong with your copy of Test::NoWarnings - try reinstalling from CPAN. Even better, try Test::Warnings which is a nicer module.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: Useless use of a constant (ict) in void context
by LanX (Saint) on Nov 15, 2013 at 13:27 UTC
    Ehm ... the code you've posted doesn't show any use strict so I can only speculate that something may be malformed in the "strict" part.

    Unicode sideeffects ?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Line 3 in .../Test/NoWarnings.pm ?

      As I said (and the error says) the suspect line is line 3 in Test::NoWarnings and it does contain use strict. I've pasted it below:

      package Test::NoWarnings; use 5.006; use strict; use warnings;

        Interestingly, line 3 is use 5.006;.

Re: Useless use of a constant (ict) in void context (perl -V)
by Anonymous Monk on Nov 15, 2013 at 23:22 UTC
    Can you post the output of perl -V?