Ron Weidner wrote:
In the program below the "for loop"  is causing the warning...
"Useless use of private variable in void context at ./uselessUse.pl line 16."


If I comment out the "for loop" like this the warning goes away...
#for($i; $i<  $n; $i++)
       ^^
The first $i is in void context


#{
     push (@some_array, $i);
#}

You could change that to:

for ( my $i = 0; $i < $n; $i++ )
{
    push @some_array, $i;
}

Or:

for my $i ( 0 .. $n - 1 )
{
    push @some_array, $i;
}

Or simply:

push @some_array, 0 .. $n - 1;



So you could write your subroutine more simply as:

sub get_some_array
{
    my $n = shift; #number of elements
    my @some_array = 0 .. $n - 1 if defined $n;
    return @some_array;
}




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to