Decades of advances in the science of computer programming have brought us to a point in language development where variable variable names have become both shunned, and in most languages, not even possible. This has come to be the case for very good reasons, thought up by some smart people, and punctuated by the collective experience of many many more average people as well as a few dummies along the way who got lucky.

Perl is one of those languages that has benefitted from the collective experience of the decades, along with the specific knowlege of a few really smart people. And that is how Perl came to have a pragma known as 'strict'. Strictures are Perl's way of keeping you from falling into the pit of despair that can come from venturing down the road of symbolic references without the realization that there is almost always a better approach. Now this isn't to say that some really really smart people (and a few average lucky ones) haven't come up with some darn good uses of symbolic references in Perl. And in fact Perl's designer(s) have left us with the capability to use them, unlike many other languages. But the odds are very strong that this isn't one of those times where it could be considered a good idea to use them.

Use an array of fourty members, or use a hash. You know, Perl's global variables themselves belong to a global symbol table hash. If it's good enough for Perl, it's good enough for you too... but don't muck with Perl's hash, get your own. :) Just because the neighborhood has its own gate doesn't mean that you shouldn't have a lock on your front door too...


Dave


In reply to Re: creating variables in a loop by davido
in thread creating variables in a loop by Anonymous Monk

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.