in reply to Data Structures Help
Ok, I'm thinking you want a multi-dimensional hash. Here's basically what I'm talking about:
That is a pre-loaded hash just to show you what the structure will look like. Of course you'll need to load that hash from scratch with your script as you read through the text file.%windows = ( "office 1" => ("120 120" => 3, "140 135" => 1, "155 135" => 1), "bedroom 2" => ("100 75" => 2, "120 180" => 1), );
So in hash %windows, key "office 1" has a value which is a *reference* to an anonymous hash (a *reference* to an anonymous hash is created by the parenthesis), and that reference refers to the anonymous hash which has these key/value's:
Then to print out the %windows hash you will need two loops - one loop to iterate through the outer hash(with keys "office 1" and "bedroom 2", and an inner loop to iterate through the hash elements within each of those outer loop elements - something like this:Key Value ------- ----- 120 120 3 140 135 1 155 135 1
***Careful - this is completely untested code, but hopefully it's close.foreach my($room, $measurements_hashref) (each %windows) { print "$room\n"; print "width\theight\tquantity\n"; foreach my($measurements, $count) (each %$measurements_hashref) +{ print "$measurements $count\n"; } }
HTH.
|
|---|