Link to home
Start Free TrialLog in
Avatar of dloszewski
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:

$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'
                     ],
}

Open in new window


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;

Open in new window


Thanks.
Avatar of ozo
ozo
Flag of United States of America image

I'm as confused about what you are trying to do as perl is.
What would you want the resulting array to look like?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial