poj gave you some real code for some faked up data, but quite likely it doesn't work for the data you have and it doesn't actually solve the problem you have either. You have actually been given most of the pieces you need and I bet you don't see how they fit together.
A hash is the right thing to solve part of the problem - it lets you group types of things together. An array is right for a different part of the problem - it lets you have a list of things of the same type. So the data structure you need is a two level hash of arrays.
The top level of the hash is keyed by shape (polygon, rectangle, ...). The values for the top level hash are references to second level hashes keyed by class (abc, def, ...). The values for the second level hashes are references to arrays. Ignoring how you parse the data to generate the data structure, you end up with something that looks like:
my %hash = ( polygon => { abc => ["0, 0, 10, 0, 12, 2", "10, 10, 20, 10, 22, 12",], def => ["3, 5, 3, 8, 7, 10"], }, rectangle => { abc => ["-10, -10, 20, 20"], def => ["22, 33, 44, 44", "1, 1, -3, -6"], } );
which can be printed out using:
for my $shape (sort keys %hash) { for my $class (sort keys %{$hash{$shape}}) { print <<LINE for @{$hash{$shape}{$class}}; <$shape class ="$class" coordinates="$_"> LINE } }
Since you've not given anything representing your real data you will have to figure out how to generate the hash from your data for yourself. However the print line above gives the syntax for accessing the array you need to add entries to for a given class and shape.
In reply to Re: Creation of Hash necessary?
by GrandFather
in thread Creation of Hash necessary?
by sandorado
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |