Gossamer Forum
Home : General : Perl Programming :

Help with hash and array!

Quote Reply
Help with hash and array!
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.Crazy


# 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>';

Last edited by:

james678: Dec 18, 2002, 6:35 PM
Subject Author Views Date
Thread Help with hash and array! james678 3678 Dec 18, 2002, 6:34 PM
Post Re: [james678] Help with hash and array!
Paul 3537 Dec 19, 2002, 2:07 AM
Post Re: [james678] Help with hash and array!
utinni 3513 Dec 22, 2002, 2:10 PM