Hello Monks,
I would like a CGI script to execute different subroutines based on the value of the variable 'button'. I would also like to pass some other variables to the subroutines and process them.
Note that I pass the same set of variables to both the subroutines, but locally assign them to different variable names. Please provide your suggestions on the approach I have followed.
... use CGI; .... # Query all variables my $button = $query->param( "button" ); my $username = $query->param( "user" ); my $region = $query->param( "region" ); my $var1 = $query->param( "var1" ); my $var2 = $query->param( "var2" ); my $var3 = $query->param( "var3" ); if ( $button eq 'first' ){ display_first( $username, $region, $var1, $var2, $var3 ); } if ( $button eq 'second' ){ display_second( $username, $region, $var1, $var2, $var3 ); } ... ... sub display_first{ my ( $s1_username, $s1_region, $s1_var1, $s1_var2, $s1_var3 ) = @_ +; ..... ..... do something with the variables... ..... } sub display_second{ my ( $s2_username, $s2_region, $s2_var1, $s2_var2, $s2_var3 ) = @_ +; ..... ..... do something with the variables... ..... }
In reply to CGI: Passing variables to a subroutine by stumbler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |