my %labels = (The first part of each hash element (the hash's key) is the value of the list item. This is the thing that eventually will be POSTed to the form and your processing script. The second part of the has element (the hash's value) is the value of the list label. This is the part that the end user will see in the drop down menu. Without this label hash, the labels of each item on the list would default to the values themselves. Now that we've prepared a hash of labels, lets look at the rest of the script:
'yes' => 'For Sure!',
'no' => 'Not for me.',
'maybe' => 'Maybe So.');
my %labels = (This produces the following output:
'yes' => 'For Sure!',
'no' => 'Not for me.',
'maybe' => 'Maybe So.');
print $cgi->popup_menu(
-name => 'your_answer',
-values => ['yes','no','maybe'],
-default => 'yes',
-labels => \%labels
);
<select name="your_answer" >So, after setting our labels hash, we call the popup_menu function. We've seen the -name attribute in the general form attributes section. Next up is an array of drop-down list values. These should be the exact same values that make up the keys in the %labels hash. The -default value references the value of the list item that you want set active when the form is loaded.
<option selected="selected" value="yes">For Sure!</option>
<option value="no">Not for me.</option>
<option value="maybe">Maybe So.</option>
</select>
Finally, the -labels hash is referenced via a pointer (notice the \ backslash in front of the call to the hash?). That's all you need for a simple drop-down list.
