Fellow Monasterians:

After Super Searching and reading a previous question, and bart's warning I still want to venture this question anyway (I think I have a legit use). But maybe there's another way.

The user clicks one of a dozen radio buttons in an HTML form, all with the name of "type" and values of 1-12 respectively. So, in my Perl:
use CGI; my $query = new CGI; my $t = $query->param('type');
So, if they clicked the 2nd button, $type = 2. For reasons too lengthy to discuss here, I want to have the equivalent of:
$type.$t = 1; #or $type2 = 1 or $type2 = true
I'm not really relying on the user's input to determine the variable name, as they are limited to a dozen radio buttons, all with set values. I just want to "build" a variable based on their choice. Otherwise, I see the only solution as:
if ($t == 1) { $type1 = 1; } elsif ($t == 2) { $type2 = 1; ... }
Seems like a bunch of code to do something that could be relatively quick (and seemingly safe). So, my questions: (1) how do I build this variable $type.$t and (2) is there a better way? Thanks in advance.

Update: davido's informative reply to the original question is worth a read by all. However, I was unable to make it work with HTML::Template (ideas are welcome, but I just need to keep the project moving) so instead adopted ishnid's solution without, I believe, jeopardizing security, at least in this case. Thanks all.

—Brad
"A little yeast leavens the whole dough."

In reply to Variable from a variable: the dark side? by bradcathey

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.