The data structure that you use depends, in part, on what you are trying to accomplish. However, from your writeup, it seems that you have several different users/entities with basically the same information describing them. I assume the program then performs a set of standard operations on the data about these users/entitites one user at a time.

Given that, I would store the info about these users in a HoH or AoH. This data structure gives you the ability to access data about the users dynamically. Once a user is determined, you can store a reference to that users data structure into a generic hash and use that reference throughout the rest of the program. That way you don't have to try and code references to specific users elsewhere in the program.

my %users = ( george => { total_money => "42", max_money => "100" }, lindsay => { total_money => "125", max_money => "1000" }, }; my $userref = \$users{$userid}; # the rest of the program accesses $userref specifically ...

PJ
unspoken but ever present -- use strict; use warnings; use diagnostics; (if needed)

In reply to Re: Dynamic variables by periapt
in thread Dynamic variables by xspikx

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.