tunafish has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
So I have what I first thought should be a simple task. I have an array of values and need to create a drop down list from them. Then, one of the values needs to be selected by default. I did this:
$countries_dropdown=join ('', map { '<option value="'.$_.'">'.$_.'</op +tion>' } @country_array); $countries_dropdown=~s/>$country_array[224}</ selected>$country_array[ +224]</;
However, this does not work! I worked around it by first assigning $country_array[224] to $temporary, and putting that into the regex, like so:
my $temporary=$country_array[224]; $countries_dropdown=~s/>$temporary</ selected>$temporary</;
That works, but I have the nagging feeling that it's not the most "elegant" solution. Is there a way to get regex to read the array value?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using array variable in regex substitution
by hbm (Hermit) on Nov 11, 2011 at 23:02 UTC | |
by tunafish (Beadle) on Nov 11, 2011 at 23:07 UTC | |
Re: Using array variable in regex substitution
by johnny_carlos (Scribe) on Nov 11, 2011 at 23:09 UTC | |
by FunkyMonk (Chancellor) on Nov 13, 2011 at 21:11 UTC |