
rGeoffrey
User
/ Moderator
Jun 22, 2001, 7:54 AM
Post #6 of 8
(573 views)
|
Consider this code...
my %select_text = (1 => ' selected', 0 => ''); %selected = map { $_ => 1 } @{$cgi_data{column}}; my $colboxes = join ("\n", qq ~<select name="column" size="8" multiple>~, (map { "<option value=\"$_\" $select_text{$selected{$_}}>$_" } qw (file url referer uagent year querystring refered parser month proto port proc searchengine refererdetail browser day addr login user hostname secdomain lstatus second)), "</select>\n"); if the array @{$cgi_data{column}} contains qw (url uagent) then the hash %selected will look like... %selected = (url => 1, uagent => 1); So when we build up the string inside the map statement, those two will get the string 'selected' from %select_text, and all the others will get nothing and print just an empty string ''. Note that when you ask about unselected things like $selected{'day'} perl may complain if you are using -w. Making it -w friendly is left as an exercise for the reader, but the 'exists' function may be involved. -- Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?
|