in reply to need to increment a $scalar while inside for loop

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'

Replies are listed 'Best First'.
Re: Re: need to increment a $scalar while inside for loop
by Anonymous Monk on Jan 02, 2002 at 08:19 UTC
    Thanks, I am real interested in using the slice function. But where does it called from? Cal