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

Question: Can I assign values to an array, and then use that array as the datasource for populating a checkbox in an HTML form? See the arrays "@list" and "@defaultScriptList" below. My way of doing this did not seem to work.
#!/usr/bin/perl use warnings; use CGI; my $co = new CGI; my @list; @list = ( 'AD.MDF.1B', 'AD.MDF.3B', 'AD.PROGMGMT', 'AD.USERMGMT', 'AD.CUSTMGMT', 'AD.PEAS.1', 'AD.PEAS.6', 'AD.REPORTS', 'MOT.MDF.3', 'MOT.MDF.5', 'XX.PROGMGMT', 'SW.MDF.3'); my @defaultScriptList; @defaultScriptList = ( "AD.USERMGMT", AD.CUSTMGMT" ); print $co->checkbox_group ( -name=>'scriptList', -values=>@list, -defaults=>@defaultScriptList, );

Replies are listed 'Best First'.
Re: Using an array to assign values in an html form
by halfcountplus (Hermit) on Oct 15, 2010 at 18:40 UTC

    I think "values" should be an array reference:

       -values=>\@list,

    As should be "defaults". A reference "refers" to an array stored in one place, meaning modifying the original array will affect subsequent actions derived from this method call -- arguments which accept an array instead of a reference copy the entire array, meaning modifying the original will not have such an effect. Also, using a reference is more efficient memory usage and speed wise particularly if the array is large.

    Ps. use strict and Taint with CGI (taint may be automatic):

    #!/usr/bin/perl -Tw use strict;