SPUG: Another hash/array question from Duane

Duane Blanchard dblanchard at gmail.com
Mon Aug 1 12:34:24 PDT 2005


Thanks to everyone who has helped me out already, I'm nearly done
(haha). I have looked at data::dumper and it will be very useful for
part of this project, but I am also using this to teach myself (with
great assistance from the group) more about data structures and
references.

Right now, I'm trying to print the zeroeth element of the zeroeth row
of the hash in the embedded hash. I've had to sanitze the data for my
client. On line 45 below, I want to print the first element of the
first row of my multidimensional array.

I've been through the perldoc for ref and reference. I've tried the
arrow operator and doubling up my dollar signs. Nothing seems to work.
Any further help would be greatly appreciated.

Thank you.

D

<line_45 question="How can I access the array that is referenced by
'val'?" note="Full sanitized code follows">
{print $outer_hash{$key}{$val}[0][0] . "\t";	# HERE IS THE STICKING POINT
</line_45>



<code>
while (my ($key, $val) = each %right_wing_zone_IDs)
{	if (ref($val) eq "HASH")
	{	print "KEY - $key\nVAL - $val\n\n";
		print $array_name;
		for ($i = 0; $i < 3; $i++)
		{	for ($j = 0; $j < 9; $j++)
			{	print $right_wing_zone_IDs{$key}{$val}[$i][$j] . "\t";	# prints
full 2D array
			}
			print "\n";
		}
	} 
	print "\n";
}


%outer_hash =	# hash of hashes and arrays
(	hash1 =>	# hash of hashes
	{	subhash1 =>	# hash of arrays of arrays
		[	["element", "YES", "element"],
			["element", "YES", "element"],
			["element", "YES", "element"],
		],
	},
	
	hash2 => # hash of hashes
	[	["element","element"],
		["element","element"],
		["element","element"],
	],
	
	hash3 => # hash of hashes
	[	["element","element"],
		["element","element"],
		["element","element"],
	],
);


while (my ($key, $val) = each %outer_hash)
{	if (ref($val) eq "HASH")
	{	print "KEY - $key\n" .
				"VAL - $val\n\n";
		for ($i = 0; $i < 3; $i++)
		{	for ($j = 0; $j < 9; $j++)
			{	print $outer_hash{$key}{$val}[$i][$j] . "\t";	# HERE IS THE STICKING POINT
			}
			print "\n";
		}
	} 
	print "\n";
}
</code>


More information about the spug-list mailing list