Reputation: 8061
I have the following code in my script:
while (my ($key, $value) = each @values) {
if ( $key < $arraySize-1) {
if ( $values[$key+1] eq "user") {
$endcon=1;
}
}
if ( ( $startcon == 1 ) && ( $endcon != 1 ) ) {
$UptimeString .= $value;
}
if ( $value eq "up") {
$startcon=1;
}
if ( $value eq "average:") {
$LoadMinOne=$values[$key+1];
}
}
While compiling it, in perl 5.14, I have no warnings, but in perl 5.10.1, I have this warning: Type of arg 1 to each must be hash (not private array) at ./uptimep.pl line 21, near "@values) "
Line 21 is while (my ($key, $value) = each @values) {
What does this mean?
Upvotes: 2
Views: 159
Reputation: 17238
as it says, each
expects a hash as an argument, not an array.
you can populate a hash first ( my %hash = @values;
) and use it as an argument ( while (my ($key, $value) = each %hash)
).
Upvotes: -1
Reputation: 91430
As said in error message, each
must have a hash for parameter, but you give it an array.
You could replace this line:
while (my ($key, $value) = each @values) {
by:
for my $key(0 .. $#values) {
my $value = $values[$key];
According to the doc each
accepts array as parameter from perl 5.12.0
Upvotes: 4