I have a survey that is 40 questions in length. All of them are arrays and look like q1 q2 q3 ... q10 q11 q12... upto q40.
So the variable I want to create will look like my $q1, my $q2 and so on and so on. And the params are identical, they are also param("q1"), param("q2), etc.
I don't want to hard code every bloody variable in there and was wondering if this could be done by a loop to create and assign all of these variables?
I was thinking something like
my $cnt = 0;
for ( 1 .. 40)
{
$cnt++;
my $q$cnt = param("q$cnt");
}
But under strict, the variables would only be accessibly until the loop is over. Can anyone come up with a way to do this?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.