to be self description ... the order of elements of data is fixed
If your main reason for considering using a hash rather than an array, is for the purpose of naming the elements, then how about naming the indices of the array elements:
use enum qw[ STATE NAME AGE ADDRESS ];
my @arrrayOfRecs = (
['US', 23, 'Andy', 'adress....' ],
['CA', 34, 'White', '........' ],
);
But I'm confused as to why you are concerned with naming the elements, if your program truly
will never pick some elements in a struct to use. Every time, I manipulate a whole struct as a piece of data, copy, delete, print etc. ?
If these are opaque units of data at this level of the code, why name the internal parts at all?
hash is unsorted, but the order of elements of data is fixed ?
Equally, if you want them named, why on earth are you concerned with the details of the internal storage "ordering"? When you eventually take these elements out of the hash -- as you must do at some point to write them to a file or display them on a screen; otherwise what purpose do they serve -- then so long as you use the names (hash keys) in the right order, then you will get the elements back in that order. (Or any other order you choose.)
Basically, your questions make no sense. You seem to be worrying about irrelevant internal details and making a mountain of it.
I think you need to step back and clarify what these "structs" really are and how they are used. Ie. Describe:
- how they are populated: where do you get the data they contain from?
- what you do with them in the program. Do you sort them? By fields? Do you select subsets of them for particular purposes?
- what do you do with them at the end of the program? Write them to a file? To the Screen? Discard them completely?
Without you telling us more about where these "structs" come from and how they are manipulated, all we can do is try to answer the literal interpretation of your questions, and at the moment, they are not making a much sense.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|