Hi Paul,
Do you have a better way of doing this? I am quite new to perl programing. Even thought it works but I believe there should be a better way of doing it. I don't think another foreach loop in a foreach loop is the right way.
I have a list of search engines in a multiple select box form. When multiple option is selected, these data will be stored separated by commas. I would like to retrieve the data and have those selected options to appear as selected in the multiple select box.
Please advise. Thanks in advance.
# Search engine hash list
my %searchengine = ('1','Yahoo','2','Google','7','AltaVista','10','Ex
cite');
# Value parsed from a multiple select box
my @searchenginemulti=split(/,/,$Form{'searchengine'});
# To arange the searchengine hash list alphabetically
%searchenginereverse = reverse %searchengine;
my $ops='<select name="searchengine" size="6" multiple>';
foreach (sort keys %searchenginereverse){
$ops .= "<option value=\"$searchenginereverse{$_}\"";
foreach $searchenginemulti(@searchenginemulti) {
if ($searchenginereverse{$_} eq $searchenginemulti){
$ops .= " selected"
}
}
$ops .= ">$_\n";}
$ops .= '</select>';
Do you have a better way of doing this? I am quite new to perl programing. Even thought it works but I believe there should be a better way of doing it. I don't think another foreach loop in a foreach loop is the right way.
I have a list of search engines in a multiple select box form. When multiple option is selected, these data will be stored separated by commas. I would like to retrieve the data and have those selected options to appear as selected in the multiple select box.
Please advise. Thanks in advance.
# Search engine hash list
my %searchengine = ('1','Yahoo','2','Google','7','AltaVista','10','Ex
cite');
# Value parsed from a multiple select box
my @searchenginemulti=split(/,/,$Form{'searchengine'});
# To arange the searchengine hash list alphabetically
%searchenginereverse = reverse %searchengine;
my $ops='<select name="searchengine" size="6" multiple>';
foreach (sort keys %searchenginereverse){
$ops .= "<option value=\"$searchenginereverse{$_}\"";
foreach $searchenginemulti(@searchenginemulti) {
if ($searchenginereverse{$_} eq $searchenginemulti){
$ops .= " selected"
}
}
$ops .= ">$_\n";}
$ops .= '</select>';