Tech Support Guy banner
  • Please post in our Community Feedback thread for help with the new forum software! If you are having trouble logging in, please Contact Us for assistance.
Status
Not open for further replies.
1 - 1 of 1 Posts

·
Registered
Joined
·
50 Posts
Discussion Starter · #1 ·
I'm having trouble getting the right values to return from a sub I'm calling from a package. I want certain variables to return based on the value of $which_svr. Right now, the values returned are whatever is in the "else" part of the sub &which_svr; it doesn't seem to check the value of $which_svr before returning the values.

I suspect I'm not seeing the forest for the trees, so any clarification on how passing variables to subs and returning values works would help this relative newbie. I've read the relevant sections in the Camel book a few times, so I'm not sure why this isn't working. Thanks!


#!/usr/local/bin/perl5_8
use strict;
use nc_rpt_library;
use DBI;
use CGI ':standard';
my $CGI = CGI->new;
$|=1;
print $CGI->header;

my $which_svr = "lock";
#by the way, I have to put the "nc_rpt_library::" in front of the
#sub call. For another package, I don't have to...
&nc_rpt_library::which_svr($which_svr);

my $err;
my $dbh = DBI->connect("dbi:Sybase:server=" . $server, $userid, $passwd) || (&dberror("connect",$err=$DBI::errstr));

#do some stuff


#this is part of my library package:
package nc_rpt_library;
use strict;
use Exporter ();
our @ISA = 'Exporter';
our @EXPORT;
use vars @EXPORT=qw/ $server $userid $passwd $which_svr/;

sub which_svr($)
{
if ( $which_svr eq "lock" )
{ $server = 'fred';
$userid = 'ethel';
$passwd = 'dog';
}
else { $server = "ricky";
$userid = "lucy";
$passwd = 'cat';
}

return $server, $userid, $passwd;
}
1;
 
1 - 1 of 1 Posts
Status
Not open for further replies.
Top