I have an array and I wish to use the elements in it as variable names. Basically, I am dynamically creating objects based upon the number of elements in the array. In order to differentiate between the object they obviously have to have unique names. This is where I use the data from the array.

The problem is that I am not sure how to do this, I have tried a number of mehods on my own to no avail.

Here is a little example of what I am doing.

for (@array){ <variable I want to create from $_> = OBJ->new; ... work using variable... }

I would also like to be able to store the newly created variable in another array for use elsewhere.

Any help is appreciated. TIA.


In reply to dynamically creating variables named after the contents of an array by gnu@perl

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.