Perl: return sub values

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Lori713

Thread Starter
Joined
Sep 8, 2003
Messages
50
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;
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top