in reply to Shortening long and dirty code
My preferred technique is to pull out duplicate (or nearly-duplicate) code into functions. Take this:
Tr( td("File: "), td( filefield( -name => 'upload', -size => 50, -maxlength => 80 ), ), ), Tr( td("File: "), td( filefield( -name => 'upload2', -size => 50, -maxlength => 80 ), ), ),
It continues for two more fields, but I'm too lazy to paste that much code. The only difference is the name field, so it's easy to turn into a function:
sub upload_field { my $name = shift; return Tr( td("File: "), td( filefield( -name => $name, -size => 50, -maxlength => 80 ), ), ); }
That turns your table into something like this:
print start_form( -method => 'post', -enctype => 'multipart/form-data', -action=> '' ), table( ( map { upload_field( "upload$_" ) } ( '', 1 .. 3 ) ), Tr( td(), td( submit( 'button', 'submit' ), ) ) ), end_form(), hr;
The same goes for processing upload fields. Remember to ask the question what's similar and what's different?
|
|---|