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

I have a form page that has select options where I submit to a Perl action page. It works but the output is like this:
California: Oakland Fresno San Diego Oregon: Portland Eugene Corvallis Utah: Salt Lake Provo
I need the output to be like this:
California: Oakland Fresno San Diego Oregon: Portland Eugene Corvallis Utah: Salt Lake Provo
Current attempt:
foreach $field (qw(California_c Oregon_o Utah_u)) { my @values = grep { ! /^\s*$/ } param($field); next unless @values; # Skip if nothing available # Establish a header line. my $header = ""; $header = "California:" if $field =~ /California_c/; $header = "Oregon:" if $field =~ /Oregon_o/; $header = "Utah:" if $field =~ /Utah_u/; #local $, = "\n"; $theData .= "$header\n@values\n\n"; } ...... <table align=\"center\"> <tr><td><pre><font face=\"Arial, Helvetica, sans-serif\" color=\"blue\ +"><strong>$theData</strong></font></pre></td><tr> </table>
Please advise.

Replies are listed 'Best First'.
Re: output from a form page with multiple selects
by Transient (Hermit) on Jun 02, 2005 at 14:41 UTC
    Change:
    $theData .= "$header\n@values\n\n";
    to
    $theData .= "$header\n".(join ("\n", @values))."\n\n";
      Thanks for your quick response and answer!!!!
Re: output from a form page with multiple selects
by ikegami (Patriarch) on Jun 02, 2005 at 17:07 UTC
    $header = "California:" if $field =~ /California_c/; $header = "Oregon:" if $field =~ /Oregon_o/; $header = "Utah:" if $field =~ /Utah_u/;

    is not very extensible. Have a look at the following:

    %states = ( 'California_c' => 'California', 'Oregon_o' => 'Oregon', 'Utah_h' => 'Utah', ... ); ... $header = $states{$field} . ':';

    or maybe just

    $header = $field; $header =~ s/_[a-z]+$//; $header .= ':';