Unexpected 1 in Error File From DBI->connect
am 22.08.2007 16:04:01 von Bob Smith
Using perl 5.8.7 and DBI 1.53 on a Linux system, the following
function outputs a spurious "1" to the web server's error file on the
DBI->connect line:
sub DBConnect
{
my ($DataBase) = @_;
my $DSN_SFS = "DBI:mysql:$DataBase"; # Data Source Name
my $DSN_USER = "root"; # ... (user name)
my $DSN_PWD = "secret"; # ... (password)
my %attr = (PrintError => 0, ## Don't report errors via warn ()
RaiseError => 0 ## Don't report errors via die ()
);
$dbh = DBI->connect ($DSN_SFS, $DSN_USER, $DSN_PWD, \%attr) or die
print "Can't open database <$DSN_SFS>"
. "
$DBI::errstr";
return $dbh;
}
Otherwise, the function works just fine. Any ideas on what could be
triggering the spurious output?
--
_________________________________________
Bob Smith -- bsmith@sudleydeplacespam.com
To reply to me directly, delete "despam".
Re: Unexpected 1 in Error File From DBI->connect
am 22.08.2007 16:12:55 von Paul Lalli
On Aug 22, 10:04 am, Bob Smith wrote:
> Using perl 5.8.7 and DBI 1.53 on a Linux system, the following
> function outputs a spurious "1" to the web server's error file
> on the DBI->connect line:
>
> sub DBConnect
> {
> my ($DataBase) = @_;
> my $DSN_SFS = "DBI:mysql:$DataBase"; # Data Source Name
> my $DSN_USER = "root"; # ... (user name)
> my $DSN_PWD = "secret"; # ... (password)
>
> my %attr = (PrintError => 0, ## Don't report errors via warn ()
> RaiseError => 0 ## Don't report errors via die ()
> );
> $dbh = DBI->connect ($DSN_SFS, $DSN_USER, $DSN_PWD, \%attr) or die
> print "Can't open database <$DSN_SFS>"
> . "
$DBI::errstr";
> return $dbh;
>
> }
>
> Otherwise, the function works just fine. Any ideas on what
> could be triggering the spurious output?
die() takes a string to print to STDERR and exits the program.
print() takes a string to print to STDOUT and returns 1 if successful.
die(print("whatever"));
will therefore print "whatever" to STDOUT, and return 1 to die().
die() will then print 1 to STDERR and exit the program.
Change die(print("whatever")) to die("whatever");
Paul Lalli
Re: Unexpected 1 in Error File From DBI->connect
am 22.08.2007 18:06:06 von Bob Smith
On 8/22/2007 10:12 AM, Paul Lalli wrote:
> On Aug 22, 10:04 am, Bob Smith wrote:
>> Using perl 5.8.7 and DBI 1.53 on a Linux system, the following
>> function outputs a spurious "1" to the web server's error file
>> on the DBI->connect line:
>>
>> sub DBConnect
>> {
>> my ($DataBase) = @_;
>> my $DSN_SFS = "DBI:mysql:$DataBase"; # Data Source Name
>> my $DSN_USER = "root"; # ... (user name)
>> my $DSN_PWD = "secret"; # ... (password)
>>
>> my %attr = (PrintError => 0, ## Don't report errors via warn ()
>> RaiseError => 0 ## Don't report errors via die ()
>> );
>> $dbh = DBI->connect ($DSN_SFS, $DSN_USER, $DSN_PWD, \%attr) or die
>> print "Can't open database <$DSN_SFS>"
>> . "
$DBI::errstr";
>> return $dbh;
>>
>> }
>>
>> Otherwise, the function works just fine. Any ideas on what
>> could be triggering the spurious output?
>
> die() takes a string to print to STDERR and exits the program.
> print() takes a string to print to STDOUT and returns 1 if successful.
>
> die(print("whatever"));
> will therefore print "whatever" to STDOUT, and return 1 to die().
> die() will then print 1 to STDERR and exit the program.
>
> Change die(print("whatever")) to die("whatever");
Excellent explanation! Many thanks!
--
_________________________________________
Bob Smith -- bsmith@sudleydeplacespam.com
To reply to me directly, delete "despam".