in reply to Help With Multiple Form Fields
merlyn gave a good answer, so I'm going to point to another issue (which you've obviously recognized, because you asked the question).
Whenever you see a pattern emerge in your code, look for an opportunity to refactor your code into something that more naturally reflects what your code is trying to do. For example, the entire chunk of code that you have from "use strict" down to assigning to the $row variable can be reduced to the following:
use strict; use CGI qw/:standard/; print header; my ( $off_shift1, $off_shift2 ); my $date = param("date") || ''; my $employee = param("employee") || ''; my $sshift = param("sshift") || ''; my $eshift = param("eshift") || ''; my $name = td( $employee ); # Calculate On shift hours and generate table cells my $total_shift = $eshift - $sshift; my $on_shift = td( 'd' ) x $total_shift; # ??? # Calculate Off Shift hours and generate cells my $td = td(''); if ( $sshift > 7 and $sshift < 25 ) { $off_shift1 = $td x ( $sshift - 8 ); } if ( $eshift > 7 and $eshift < 25 ) { $off_shift2 = $td x ( 24 - $eshift ); } my $row = "$name$off_shift1$on_shift$off_shift2";
That's a lot easier to read and maintain. Now, why did I test to ensure that $eshift and $sshift were in the correct range? Because validating your input data is almost always one of the first things you want to do. Read perlsec for more information about taint checking and ensuring that the data you read doesn't do horrible things to you later.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid) Re: Help With Multiple Form Fields
by nlafferty (Scribe) on Feb 13, 2002 at 19:12 UTC |