in reply to How to loop through CGI params and insert into a heredoc?
Done. No need to sort, hash populated, missing fields reported. Oh. wait...my @sorted = qw( 02_org_name 03_org_addr1 03_org_addr2 04_org_city ... ); my %swip_data; @swip_data{@sorted} = map { defined $cgi->param($_) and $cgi->param($_) or print "You must define a $_.<br>" and '' } @sorted;
<update>... you are printing the form fields first:
my @sorted = qw( 02_org_name 03_org_addr1 03_org_addr2 04_org_city ... ); my %swip_data; my @missing; @swip_data{@sorted} = map { print "$_ :" . $cgi->textfield(-name => "$_") . "<br>"; defined $cgi->param($_) and $cgi->param($_) or push @missing, $_ and ''; } @sorted; @missing and print "You must define these fields: ",join(', ', @missin +g),".<br>\n";
No need for double quotes here:
if (defined $cgi->param("$_")) {
and no need for explicit concatenation here:
print "You must define a $_." . "<br>"; print "You must define a $_.<br>"; # less noise
Unless you use $arin_tmpl elsewhere, just say
print <<END_TMPL;
If you populate the array first, and from there your hash, you don't need n_ to maintain order.
</update>
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|