Unexpected 1 in Error File From DBI->connect

Discussion in 'Perl Misc' started by Bob Smith, Aug 22, 2007.

  1. Bob Smith

    Bob Smith Guest

    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 --

    To reply to me directly, delete "despam".
     
    Bob Smith, Aug 22, 2007
    #1
    1. Advertising

  2. Bob Smith

    Paul Lalli Guest

    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 &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
     
    Paul Lalli, Aug 22, 2007
    #2
    1. Advertising

  3. Bob Smith

    Bob Smith Guest

    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 &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 --

    To reply to me directly, delete "despam".
     
    Bob Smith, Aug 22, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ulloa
    Replies:
    1
    Views:
    545
    Juha Laiho
    Jul 22, 2004
  2. Paul Vudmaska

    dbi - install - connect error

    Paul Vudmaska, May 9, 2004, in forum: Ruby
    Replies:
    2
    Views:
    103
    Michael Neumann
    May 10, 2004
  3. Jerome Hauss
    Replies:
    0
    Views:
    184
    Jerome Hauss
    Oct 13, 2004
  4. Asby

    Mason, DBI, and DBI::Pg

    Asby, Jul 24, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    189
  5. Ed_Zep
    Replies:
    2
    Views:
    387
    Ron Reidy
    Nov 13, 2003
Loading...

Share This Page