Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Unexpected 1 in Error File From DBI->connect

Reply
Thread Tools

Unexpected 1 in Error File From DBI->connect

 
 
Bob Smith
Guest
Posts: n/a
 
      08-22-2007
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?

--
_________________________________________
Bob Smith -- http://www.velocityreviews.com/forums/(E-Mail Removed)

To reply to me directly, delete "despam".
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-22-2007
On Aug 22, 10:04 am, Bob Smith <(E-Mail Removed)> 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 &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

 
Reply With Quote
 
 
 
 
Bob Smith
Guest
Posts: n/a
 
      08-22-2007
On 8/22/2007 10:12 AM, Paul Lalli wrote:
> On Aug 22, 10:04 am, Bob Smith <(E-Mail Removed)> 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 &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");


Excellent explanation! Many thanks!

--
_________________________________________
Bob Smith -- (E-Mail Removed)

To reply to me directly, delete "despam".
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk insert - error: Unexpected end-of-file (EOF) encountered in data file. AB@ ASP .Net 2 04-17-2007 03:37 PM
Error: File /trxweb/trxweb.asp Unexpected error.(E06D7363) Vaquar ASP General 1 03-20-2007 04:29 PM
Long call to webservice generates "underlying connection was closed: An unexpected error occurred on a receive."Error Techsatish ASP .Net Web Services 1 09-22-2006 03:18 AM
Error when calling a web service (The underlying connection was closed: An unexpected error occurred on a receive.) Franck ASP .Net Web Services 0 11-12-2003 03:43 PM
fatal error CS0007: Unexpected common language runtime initialization error -- Polo Lee ASP .Net 0 07-07-2003 01:24 AM



Advertisments