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.
  1. my %functions = ( 'status'       => \&create_new_request_status,  
  2.                   'barcode'      => \&update_request_barcode,  
  3.                   'lab_director' => \&update_request_lab_director,  
  4.                   'library_type' => \&update_request_library_type,  
  5.                   'request_name' => \&update_request_name,  
  6.                   'source'       => \&update_request_source,  
  7.                   'species'      => \&update_request_species, ) ;  
  8.   
  9. my $out_url = 'request_info.cgi' ;  
  10. $out_url .= '?test=1' if defined $cgi->param( 'test' ) ;  
  11. $output .= $cgi->h2( $cgi->a( { href => $out_url }, 'Request Table' ) ) ;  
  12.   
  13. ## show specific run info  
  14. if ( 0 ) { }    # BLANK to make adding and changing elsifs easier  
  15. elsif ( defined $cgi->param( 'request_id' ) ) {  
  16.     for my $key ( $cgi->param() ) {  
  17.         if ( $functions$key } ) {  
  18.             my $data ;  
  19.             $data->{ request_id } = $cgi->param( 'request_id' ) ;  
  20.             if ( $key eq 'status' ) {    # status is different  
  21.                 for my $word ( qw{ status program notes } ) {  
  22.                     $data->{ $word } = $cgi->param( $word ) ;  
  23.                     }  
  24.                 $functions$key }->( $data ) ;  
  25.                 }  
  26.             else {  
  27.                 $data->{ val } = $cgi->param( $key ) ;  
  28.                 $functions$key }->( $data ) ;  
  29.                 }  
  30.             }  
  31.         }  
  32.     my $request_id = $cgi->param( 'request_id' ) ;  
  33.     $output .= $cgi->h2( 'Request #' . $request_id ) ;  
  34.     $output .= $cgi->div( show_request( $request_id ) ) ;  
  35.     }  
  36. else {  
  37.     $output .= $cgi->div( show_list() ) ;    # show full table  
  38.     }  
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