Anytime you're tempted to start manipulating variables by their names, or tempted to name variables something like @array1, @array2, etc., you're probably going down the wrong road.

Instead of @array1, @array2, etc., have a single array that holds references to the individual datastructures. Instead of @array1 = ( list ), how about $array->[1] = [ list ]? The difference is that with the first method you're going to end up using symbolic references needlessly, and probably introducing a heightened potential for bugs, unmaintainable code, and security breeches into your script. With the second method, you're using real "hard" references how they were intended to be used, and will end up with cleaner, more maintainable, less buggy, and more secure code.

Naming variable names programatically is almost always a bad idea, and creating lists of soft references begs the question why aren't we just using an array of hard references in the first place?

I hope this is helpful in describing that there is a "better way to do it" out there.


Dave


In reply to Re: Unique Array from DB by davido
in thread Unique Array from DB 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.