in reply to Initializing a hash using a foreach loop
I've also removed unnecessary quotes and converted to a more Perlesque foreach loop. An alternative method would be to use map to assign the whole hash:%ServerStatus = (); foreach my $i (0..$num) { $ServerStatus{$Ip[$i]} = [$Names[$i], 'unknown']; }
%ServerStatus = map {($Ip[$_], [$Names[$_], 'unknown'])} 0..$num;
|
---|