develooper Front page | perl.perl5.porters | Postings from September 2016

[perl #123665] 'Useless use of a constant in void context' iscompile-time but not syntax warning

Thread Next
From:
Redfred Garett via RT
Date:
September 14, 2016 18:40
Subject:
[perl #123665] 'Useless use of a constant in void context' iscompile-time but not syntax warning
Message ID:
rt-4.0.24-19080-1473856663-787.123665-14-0@perl.org
The functions in this section can serve as terms in an expression.
       They fall into two major categories: list operators and named unary
       operators.  These differ in their precedence relationship with a fol-
       lowing comma. 
There are two issues at hand here.

    Why does use bigint; 1; warn in void context?
    Why is the constant being executed in void context in the first place?

$ perl -c -we'1 while sub_with_side_effects();'
-e syntax OK

$ perl -c -we'use bigint; 1 while sub_with_side_effects();'
Useless use of a constant (1) in void context at -e line 1.
-e syntax OK



OK, so - from the comments - you're comparing two arrays.

Presumably inside your loop you're doing something like:

 if ( $name[$j] == $name_mod[$k] ) { 

So my suggestion would be - don't do it like that:

for ( my $index = 0; $index < @name and $index < @name_mod; $index++ ) { 
    if ( $name[$index] == $name_mod[$index] ) { 
         #do something
     }
}

Or perhaps: each_array

my $ea = each_array(@name, @name_mod);
while ( my ($cur_name, $cur_name_mod ) = $ea->() )   { .... }



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About