stumbler has asked for the wisdom of the Perl Monks concerning the following question:
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... ..... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI: Passing variables to a subroutine
by Herkum (Parson) on Jan 04, 2007 at 21:29 UTC | |
by Anonymous Monk on Jan 05, 2007 at 01:41 UTC | |
by stumbler (Acolyte) on Jan 04, 2007 at 21:52 UTC | |
by ikegami (Patriarch) on Jan 04, 2007 at 22:17 UTC | |
by friedo (Prior) on Jan 04, 2007 at 23:09 UTC | |
|
Re: CGI: Passing variables to a subroutine
by Fletch (Bishop) on Jan 04, 2007 at 21:52 UTC |