Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2010/08/19

Copy/Paste: The First Step Is To Admit You Have A Problem

Thanks to Juster, I have come up with a better way to handle it.


my %functions = ( 'status' => \&create_new_request_status,
'barcode' => \&update_request_barcode,
'lab_director' => \&update_request_lab_director,
'library_type' => \&update_request_library_type,
'request_name' => \&update_request_name,
'source' => \&update_request_source,
'species' => \&update_request_species, ) ;

my $out_url = 'request_info.cgi' ;
$out_url .= '?test=1' if defined $cgi->param( 'test' ) ;
$output .= $cgi->h2( $cgi->a( { href => $out_url }, 'Request Table' ) ) ;

## show specific run info
if ( 0 ) { } # BLANK to make adding and changing elsifs easier
elsif ( defined $cgi->param( 'request_id' ) ) {
for my $key ( $cgi->param() ) {
if ( $functions{ $key } ) {
my $data ;
$data->{ request_id } = $cgi->param( 'request_id' ) ;
if ( $key eq 'status' ) { # status is different
for my $word ( qw{ status program notes } ) {
$data->{ $word } = $cgi->param( $word ) ;
}
$functions{ $key }->( $data ) ;
}
else {
$data->{ val } = $cgi->param( $key ) ;
$functions{ $key }->( $data ) ;
}
}
}
my $request_id = $cgi->param( 'request_id' ) ;
$output .= $cgi->h2( 'Request #' . $request_id ) ;
$output .= $cgi->div( show_request( $request_id ) ) ;
}
else {
$output .= $cgi->div( show_list() ) ; # show full table
}
Of course, if I had another table showing what fields I need to put into each input hash, that would make the code even simpler.

No comments:

Post a Comment