esharris has asked for the wisdom of the Perl Monks concerning the following question:

Suppose I have a field that takes multiple values, like a checkbox group. How do I use CGI::param to clear out the parameter values? Based on the documentation, I thought CGI::param(-name => 'xxx', -value => []); would be the solution.
#!/usr/bin/perl -w use strict; use CGI; CGI::param(-name => 'xxx', -value => [1,2,3]); print join(',', CGI::param(-name => 'xxx'))."\n"; CGI::param(-name => 'xxx', -value => []); print join(',', CGI::param(-name => 'xxx'))."\n";
Unfortunately, the preceding code prints the following.
1,2,3 1,2,3

Replies are listed 'Best First'.
Re: Clearing multi-valued parameters using CGI.pm
by wfsp (Abbot) on Jan 26, 2006 at 15:48 UTC
    Perhaps look at the docs and scoll down to DELETING A PARAMETER COMPLETELY.
      I sent an e-mail to Lincoln Stein about this issue. In his reply, he said this is a bug in the code. He thanked me for finding the bug and he fixed the bug in the next version of CGI.
Re: Clearing multi-valued parameters using CGI.pm
by chargrill (Parson) on Jan 26, 2006 at 15:37 UTC
    This seems to work for me:
    CGI::param(-name => 'xxx', -value => "");
    ---chargrill
    $/ = q#(\w)# ; sub sig { print scalar reverse join ' ', @_ } + sig map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu +" );