Unexpected 1 in Error File From DBI->connect

B

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>"
. "<br />$DBI::errstr";
return $dbh;
}

Otherwise, the function works just fine. Any ideas on what could be
triggering the spurious output?
 
P

Paul Lalli

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 &lt;$DSN_SFS&gt;"
. "<br />$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
 
B

Bob Smith

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top