Why are you using a hash in this case? It looks like you are using it where one would use a struct in C. Now, either of two things could be the case: you just have a single hash with this role, or it's one of many. In the first case, you can avoid the hash altogether, and just use variables, $name, $age, etc. If you have more of them, just turn them inside-out. Say you would normally have %person1, %person2, %person3, etc, each with an age, a name, and perhaps more, something like:
my (%person1, %person2, %person3, ...); $person1 {name} = "..."; $person1 {age} = ...; $person2 {name} = "..."; $person2 {aeg} = ...; # Oopsie. $person3 {name} = "..."; $person3 {age} = ...;
Instead of hashes for the entities, and attributes as the keys, make hashes for the attributes, using the entities as attributes - just make sure the entities are unique.
my (%age, %name); my $entitie_count = 0; my $person1 = ++ $entitie_count; my $person2 = ++ $entitie_count; my $person3 = ++ $entitie_count; $name {$person1} = "..."; $age {$person1} = ...; $name {$person2} = "..."; $aeg {$person2} = ...; # Compile time error with use strict. $name {$person3} = "..."; $age {$person3} = ...;

Abigail


In reply to Re: hash, a troublemaker? by Abigail-II
in thread hash, a troublemaker? by Doraemon

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.