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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.