|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: problem with using variable
Date: Jul 21 2003 6:44AM
On Sat, 2003-07-19 at 17:27, David Owen wrote:
> On Fri, 2003-07-18 at 10:38, Sabherwal, Balvinder (MBS) wrote:
> > my $oExcel = new Spreadsheet::ParseExcel;
> > my (@fl , $usrfname , $usrdbid , $data , $mmsg_syb , $pwd , $mmsg_ora );
> >
> > if ( ! open( PW , 'c:\tmp\dbpass_nj2') ) { die "Error : $!\n" ; } ## get the
> > password for dbuser
> > @fl= ; ## get the password for dbuser
>
> > foreach $pwd ( @fl )
> > {
> > chomp($pwd); ## Remove new line characters at the end.
> > print "$pwd \n";
> > }
>
> Try a 'print "$pwd\n";' just here. What is it set to? I suspect that
> $pwd is being unset by the loop.
Yes, that's exactly what happens - the foreach loop sets the value of
$pwd for use inside the loop, but it clears it before exiting the loop.
If your file has a single password in it I'd maybe use something like
this:
{
local $/ = undef; # read the entire file in one go
open(IN, "/tmp/passwd") || die "Can't open pwd file: $!";
$pwd = ;
$pwd =~ s/\s*$/; # remove any trailing spaces
chomp($pwd);
close(IN);
}
> > my $dbh=Sybase::CTlib->ct_connect("DBUSER","$pwd","SYB_NJ2");
There's no need to quote $pwd here - I'd write:
my $dbh = Sybase::CTlib->ct_connect("DBUSER", $pwd, "SYB_NJ2");
Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler@peppler.org http://www.mbay.net/~mpeppler
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.mbay.net/~mpeppler/resume.html
|