ag4ve has asked for the wisdom of the Perl Monks concerning the following question:
so, i'm thinking my understanding of variables is somehow off. when i pass my ($int1, $int2) to a subroutine like somesub($int1, $int2) and call it inside the sub with ($int1, $int2) = @_ they become are not defined. to more explicit, here's extracts of my code:
my ($ownsel, $sortby, $letter, $ascdesc, $t); ... if ( $cgi->param ) { if ( defined ( $cgi->param( 'sortby' ) ) ) { $sortby = $_; } else { $sortby = "name"; } if (defined ( $cgi->param( 'ascdesc' ) ) ) { $ascdesc = $_; } else { $ascdesc = "desc"; } if (defined ( $cgi->param( 'letter' ) ) ) { $letter = $_; } else { $letter = " "; } ownertbl( $sortby, $ascdesc, $letter ); } else { homepage(); } ... sub ownertbl { ( $sortby, $ascdesc, $letter ) = @_; ... $sort = "ORDER BY " . $sortby . $ascdesc; ... print STDERR "base = $base, sort = $sort, sortby = $sortby, ascdes +c = $ascdesc, letter = $letter\n";
this is a cgi script, so from apache's error.log, i'm getting this:
Use of uninitialized value $ascdesc in concatenation (.) or string at +/var/www/cgi-bin/ownertbl.pl line 71., base = http://192.168.15.222/cgi-bin/ownertbl.pl, sort = ORDER BY name +, sortby = name, ascdesc = , letter = ,
line 71 is the $sort = "ORDER BY......" i've dealt with this before by just doing $_[0], but this is not preferred when dealing with multiple variables. where am i messing up here.
btw, this seemed relevant but didn't really answer my question:
http://perlmonks.org/index.pl?node_id=192506
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: passing variables to a sub
by morgon (Priest) on Oct 16, 2010 at 02:35 UTC | |
by ag4ve (Monk) on Oct 16, 2010 at 04:18 UTC | |
|
Re: passing variables to a sub
by chromatic (Archbishop) on Oct 16, 2010 at 03:31 UTC | |
by ag4ve (Monk) on Oct 16, 2010 at 04:25 UTC | |
|
Re: passing variables to a sub
by eyepopslikeamosquito (Archbishop) on Oct 16, 2010 at 04:49 UTC | |
by ag4ve (Monk) on Oct 16, 2010 at 05:13 UTC | |
|
Re: passing variables to a sub
by TomDLux (Vicar) on Oct 16, 2010 at 14:18 UTC | |
by Anonymous Monk on Oct 16, 2010 at 16:34 UTC | |
by graff (Chancellor) on Oct 17, 2010 at 00:49 UTC |