dloszewski
asked on
Copy hash to multi-dimensional array
Hello,
Could someone tell me how I would copy a hash (including the keys) to a mulch-dimensional array?
I have this as my hash, stored in %pids:
I'm using the following to copy the hash to the array but is keep giving me: "Can't use string ("743") as an ARRAY ref while "strict refs""
Thanks.
Could someone tell me how I would copy a hash (including the keys) to a mulch-dimensional array?
I have this as my hash, stored in %pids:
$VAR1 = {
'743' => [
'00:1'
],
'20687' => [
'01:3'
],
'27186' => [
'15:3'
],
'6929' => [
'12:0'
],
'24771' => [
'09:0'
],
'11804' => [
'01:1'
],
'27683' => [
'08:3'
],
'14976' => [
'04:3'
],
}
I'm using the following to copy the hash to the array but is keep giving me: "Can't use string ("743") as an ARRAY ref while "strict refs""
my @array = keys %pids;
my $counter = 0;
foreach $var(keys %pids){
$counter = 0;
while (@array){
if ($array[$counter] =~ $var){
$array[$counter][0] = @{$pids{$var}};
$counter++;
}
}
}
print Dumper \@array;
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What would you want the resulting array to look like?