Next | Program Repair Shop | 280 |
if ($FORM{'h01'}) {$checked01 = " CHECKED "} ... if ($FORM{'h06'}) {$checked06 = " CHECKED "}
Several people suggested alternatives such as:
for $i (1..6) { $checked[$i] = 'CHECKED' if $FORM{"h0$i"}; }
This misses the point
We can see from this that $FORM{'h06'} is essentially a boolean variable
True if the box was checked, false if not
That's precisely what $checked06 is too
Why have two variables to record the same information?
Just use $FORM{'h06'} everywhere you would have used $checked06
Or possibly: $FORM{'h06'} && " CHECKED "
Or change the HTML:
<input type=checkbox value=' CHECKED '>
Or a function:
sub checked { $FORM{$_[0]} ? ' CHECKED ' : '' }
Next | Copyright © 2002 M. J. Dominus |