Your best way to achieve what you desire would be to make use of a more complex data structure such as an array or a hash. The other option of modifying the scalar variable name itself (symbolic references), while it can certainly be done, is not the best way to implement such a solution - To find out why symbolic references are bad, have a read through the links referenced in this node.

For example using an array:

my @name_menu; for (0..$elements) { splice( @name_menu, $_, 0, qq{ <select size="1" name="M$_"> $fname <option>GUEST</option> <option selected>Select a member</option> </select> } ) }

Each element within the array could subsequently be called as $name_menu[0], $name_menu[1], etc. Alternatively, if you were to use a hash data structure, which would result in faster look ups, you might use code similar to the following:

my %name_menu; for (0..$elements) { $name_menu{$_} = qq{ <select size="1" name="M$_"> $fname <option>GUEST</option> <option selected>Select a member</option> </select> }; }

Each element within the hash could subsequently be called as $name_menu{0}, $name_menu{1}, etc.

Good luck.

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'


In reply to Re: need to increment a $scalar while inside for loop by rob_au
in thread need to increment a $scalar while inside for loop 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.