Sorry, I've looked at your code several times and it looks like nonsense to me. For example, it makes no sense to pass $sortby into sub ownertbl and then assign it to itself.

I suggest you start your script with:

use strict; use warnings;
then define all your subroutines, then your mainline (including any file-scope lexical variable declarations). For example:
use strict; use warnings; # Put your subs here before any file-scope variables. # That makes it clearer that each sub does not depend on # anything other than the parameters passed to it. sub ownertbl { my ( $sortby, $ascdesc, $letter ) = @_; # added leading "my" # ... } # put your other subs here... # Now define your lexical variables after the subs... my ($ownsel, $sortby, $letter, $ascdesc, $t); if ( $cgi->param ) { if ( defined ( $cgi->param( 'sortby' ) ) ) { $sortby = $_; # this looks wrong to me } else { $sortby = "name"; } if (defined ( $cgi->param( 'ascdesc' ) ) ) { $ascdesc = $_; # ditto } else { $ascdesc = "desc"; } if (defined ( $cgi->param( 'letter' ) ) ) { $letter = $_; # ditto } else { $letter = " "; } ownertbl( $sortby, $ascdesc, $letter ); # now these three variables + are properly passed to the sub } else { homepage(); }


In reply to Re: passing variables to a sub by eyepopslikeamosquito
in thread passing variables to a sub by ag4ve

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.