It's a perfectly reasonable representation for the data, depending on how you want to handle the data. In my own work, I very frequently deal with arrays of hasherefs. Granted, though, it's not the only way, or necessarily the best. That's going to depend on what you want to do with it.
This can be a good way to represent very simple objects or rows of a database table. However, if you want to have a data structure which, in and of itself, enforces the homogeneity of the individual rows/objects, then you can go with an array of array-refs:
And, if you like, you can keep the column name => column index map in a hash:my @data = ( [ 'Mrs', 'Linda', 'Carolo', '201', '148', 'she@borg.org' ], [ 'Mrs', 'Jean', 'Andronlo', '317', '167', 'j@alo.com' ], # etc );
and then you can reference the items in a row:my %index = ( title => 1, first => 2, last => 3, room => 4, phone => 5, email => 6, );
There's also something in perl called a "psuedo hash" which is a means by which the language does what I showed above (using a name as an index in an array, rather than a number), but I'd avoid them if possible.foreach my $row (@data) { print "$row->[$column{title}] $row->[$column{first}] $row->[$column +{last}]\n"; }
Anyway, that (above) is just one other example of how you might store a table... ultimately the "best" method for storing your data table will be dictated by what you intend to do with it. However, the array of hashrefs is about the simplest, most flexible way (though some people might gripe about the "wasteful"ness (both in space and time) of using a hash-lookup for each element of each row).
In reply to Re: Is this a reasonable data structure?
by etcshadow
in thread Is this a reasonable data structure?
by Theo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |