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:

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.

In reply to Re^3: c-like struct? by BrowserUk
in thread c-like struct? by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.