grittyminder
IS-IT--Management
I'm assigning an array as a value to an associative array (they key is a string). When I try to get the array value using the key... well, it seems I can get it but I can't assign it. Here's what I wrote:
foreach $key (keys %nameTable){
my $outputStr = "";
my @valueArray = @nameTable{$key};
#print "VALUEARR: " . @valueArray . "\n";
#print "VALUEARR: " . @nameTable{$key} . "\n";
for(my $i=0; $i < @valueArray; $i++){
my $value = $valueArray[$i];
$outputStr = $outputStr . $value;
if($i < @valueArray-1){
$outputStr = $outputStr . $DELIMETER;
}
}
print "$outputStr\n";
}
So the problem is that @nameTable{$key} = 8 (i.e. the length of the array associated with $key) whereas @valueArray = 1. It seems that the array being returned from %nameTable is not being assigned correctly to @valueArray. What is going on?
foreach $key (keys %nameTable){
my $outputStr = "";
my @valueArray = @nameTable{$key};
#print "VALUEARR: " . @valueArray . "\n";
#print "VALUEARR: " . @nameTable{$key} . "\n";
for(my $i=0; $i < @valueArray; $i++){
my $value = $valueArray[$i];
$outputStr = $outputStr . $value;
if($i < @valueArray-1){
$outputStr = $outputStr . $DELIMETER;
}
}
print "$outputStr\n";
}
So the problem is that @nameTable{$key} = 8 (i.e. the length of the array associated with $key) whereas @valueArray = 1. It seems that the array being returned from %nameTable is not being assigned correctly to @valueArray. What is going on?