What I am trying to do may be stupid/daft/wrong-headed; any alternate methods would be appreciated.

I wanted to put a variable name together dynamically inside a sub, based on the arguments of that sub. For instance, if the first argument is "example" and the second is "other", I wanted to define a variable called $exampleother1, or $exampleother2. I can concatenate variables and strings, but I don't know how to concatenate a string and then make it a variable name.

Because this seems hard/strange I suspect that it is also idiotic, but I think I'm better off asking for the wisdom (and tolerance) of the monks then to sit in ignorance.

Update: Yep, stupid, daft and wrong-headed. Using a data structure to capture my cases makes more sense then trying to build case-specific variables. I should stop asking questions and just re-read the Llama book each time I find something difficult. Thanks for the suggestions, guidance and references.


In reply to Dynamically Building Variable Names by willyyam

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.