eval-Question

Discussion in 'Perl Misc' started by Reinhard Glauber, Feb 1, 2006.

  1. I have a sub called "insert".
    In the main - Programm I call this subroutine. The Problem is, that I get an DB-Errormessage.
    That's something I don't want. That's the reason why I tried to write the code with "eval".
    The error occures, when there is a duplicate value.
    The error is not the Problem. The Problem is, that I dont want Perl to write me all the time this Errorcode.
    A simple "Error" is enough for me...
    So look at the Code...

    sub insert
    {
    ........

    eval {

    $dbh = DBI->connect('DBI:mysq blabla');
    my $sql = "INSERT INTO blabla";
    my $sth = $dbh->prepare( $sql );
    $sth->execute();

    };

    if (!$@) { $isok = "... ok\n";}
    if ($@) {$isok = "Error\n";}

    } # end of sub


    $res = insert ($value);
    print $isok;



    Any Hints for a Perl-Newbie ??

    Thanks a lot
     
    Reinhard Glauber, Feb 1, 2006
    #1
    1. Advertising

  2. Reinhard Glauber

    Guest

    Reinhard Glauber wrote:
    > The error is not the Problem. The Problem is, that I dont want Perl to write me all the time this Errorcode.


    > $dbh = DBI->connect('DBI:mysq blabla');


    Your question is not completely clear to me, but you may get what you
    want by changing your connect method a bit:

    $dbh = DBI->connect('DBI:mysq blabla', PrintError => 0);

    If you do that, you need to catch and print errors yourself with
    something like this (from the DBI docs):

    eval {
    ...
    $sth->execute();
    ...
    };
    if ($@) {
    # $sth->err and $DBI::err will be true if error was from DBI
    warn $@; # print the error
    ... # do whatever you need to deal with the error
    }

    --
    http://DavidFilmer.com
     
    , Feb 1, 2006
    #2
    1. Advertising

  3. "Reinhard Glauber" <> wrote in
    news:43e12c46$0$16303$-online.net:

    > I have a sub called "insert".
    > In the main - Programm I call this subroutine. The Problem is, that I
    > get an DB-Errormessage. That's something I don't want. That's the
    > reason why I tried to write the code with "eval". The error occures,
    > when there is a duplicate value. The error is not the Problem. The
    > Problem is, that I dont want Perl to write me all the time this
    > Errorcode. A simple "Error" is enough for me...
    > So look at the Code...
    >
    > sub insert
    > {
    > ........
    >
    > eval {
    >
    > $dbh = DBI->connect('DBI:mysq blabla');


    What is the specific blabla you use in this instance?

    Have you read the posting guidelines posted here regularly? They contain
    invaluable information on how to compose a post that conveys information
    that helps us diagnose the problem.

    Have you read the DBI documentation?
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Feb 1, 2006
    #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. Eric Newton
    Replies:
    3
    Views:
    9,480
    Brock Allen
    Apr 4, 2005
  2. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    562
    Karl Seguin [MVP]
    Jun 16, 2006
  3. Alex van der Spek

    eval('07') works, eval('08') fails, why?

    Alex van der Spek, Jan 8, 2009, in forum: Python
    Replies:
    6
    Views:
    1,487
    Bruno Desthuilliers
    Jan 8, 2009
  4. Liang Wang
    Replies:
    8
    Views:
    141
    Ben Morrow
    Feb 2, 2008
  5. Marc Girod

    to eval or not to eval?

    Marc Girod, Apr 19, 2011, in forum: Perl Misc
    Replies:
    2
    Views:
    164
    Marc Girod
    Apr 19, 2011
Loading...

Share This Page