Multiline die

Discussion in 'Perl Misc' started by Samik Raychaudhuri, Oct 15, 2004.

  1. Hello,
    I have quick question. I want to shwo a multiline die msg, and I am not getting it.
    I am trying:
    $sth=$dbh->prepare($querystr) || $class->{errstr}=DBI->errstr; die "Query: $querystr, ".DBI->errstr;
    AND
    $sth=$dbh->prepare($querystr) || {$class->{errstr}=DBI->errstr; die "Query: $querystr, ".DBI->errstr;}

    None works. What is the way?
    Regards.
    --

    To email me, replace 'K' with 'e' in the 'From' field.
     
    Samik Raychaudhuri, Oct 15, 2004
    #1
    1. Advertising

  2. Samik Raychaudhuri <> wrote in
    news:ckook4$2pa$:

    > Hello,
    > I have quick question. I want to shwo a multiline die msg, and I am
    > not getting it. I am trying:
    > $sth=$dbh->prepare($querystr) || $class->{errstr}=DBI->errstr; die
    > "Query: $querystr, ".DBI->errstr; AND
    > $sth=$dbh->prepare($querystr) || {$class->{errstr}=DBI->errstr; die
    > "Query: $querystr, ".DBI->errstr;}
    >
    > None works. What is the way?
    > Regards.


    Why do you want to write hard to read code?

    Why don't you read the DBI docs?

    The following is easy to read

    $sth = $dbh->prepare($querystr)
    or die $dbh->errstr;

    Notice the $dbh.

    Yours is not.

    Life is much simpler if you use the appropriate amount of whitespace and
    structure.

    unless($dbh->prepare($querystr)) {
    $class->{errstr} = $dbh->errstr;
    die "Query: $querystr, ", $dbh->errstr;
    }

    Now, while I do hope this helps you, let me point out that you should
    read the posting guidelines for this group before you post again. They
    are posted here regularly, and can be found on the WWW:

    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

    Sinan.
     
    A. Sinan Unur, Oct 15, 2004
    #2
    1. Advertising

  3. Samik Raychaudhuri

    Paul Lalli Guest

    "Samik Raychaudhuri" <> wrote in message
    news:ckook4$2pa$...
    > Subject: Multiline die


    Your post seems to have little to do with your Subject. Please put the
    subject of your post in the Subject of your post.

    > I have quick question. I want to shwo a multiline die msg, and I am

    not getting it.
    > I am trying:
    > $sth=$dbh->prepare($querystr) || $class->{errstr}=DBI->errstr; die

    "Query: $querystr, ".DBI->errstr;
    > AND
    > $sth=$dbh->prepare($querystr) || {$class->{errstr}=DBI->errstr; die

    "Query: $querystr, ".DBI->errstr;}

    I don't understand why you're bothering to set this $class->{errstr}
    value when you immediately die right after it. What is the point of
    this statement?

    > None works.


    That is a remarkably poor error description. How is it not working?
    What is it doing that you didn't expect it to do?

    Running your (first) code, I get
    Can't modify logical or (||) in scalar assignment

    That's because || has a higher precedence than =. Switching to 'or'
    instead of || would at least solve the compliation error (but would not
    do what you actually want it to do)

    In the second example, you've forgotten the keyword 'do' before the
    block.

    > What is the way?


    I'd recommend avoiding the "boolean operators for all control-flow"
    mentality.

    unless ($sth=$dbh->prepare($querystr)){
    $class->{errstr}=DBI->errstr;
    die "Query: $querystr, ".DBI->errstr;
    }

    Though, again, I don't understand the point of the first statement.

    Paul Lalli
     
    Paul Lalli, Oct 15, 2004
    #3
  4. Thanks very much for the replies. I learnt quite a few things from both the posts. I will surely be careful about the subject in future.

    On 10/15/2004 10:48 AM, Paul Lalli wrote:
    >
    > I don't understand why you're bothering to set this $class->{errstr}
    > value when you immediately die right after it. What is the point of
    > this statement?
    >


    This is actually a package which is getting used in another program. I need the error string outside the package, that is the reason I am doing this. I guess I should have just done a return rather than die, as it does the same thing in this context.

    >
    >>None works.

    >
    >
    > That is a remarkably poor error description. How is it not working?
    > What is it doing that you didn't expect it to do?
    >
    > Running your (first) code, I get
    > Can't modify logical or (||) in scalar assignment
    >

    I also got this. I should have CCP-ed this message. Will do it henceforth.

    > That's because || has a higher precedence than =. Switching to 'or'
    > instead of || would at least solve the compliation error (but would not
    > do what you actually want it to do)
    >

    I didn't know that 'or' and '||' has different precedence (guess didn't read between lines !!). I used to think it's just a matter of readability why one uses 'or' than '||'.

    > In the second example, you've forgotten the keyword 'do' before the
    > block.
    >
    >
    >>What is the way?

    >
    >
    > I'd recommend avoiding the "boolean operators for all control-flow"
    > mentality.
    >
    > unless ($sth=$dbh->prepare($querystr)){
    > $class->{errstr}=DBI->errstr;
    > die "Query: $querystr, ".DBI->errstr;
    > }
    >

    This was suggested by the first post too. I am going to follow this, thanks.
    Have a nice weekend.
    --
    Samik Raychaudhuri
    To email me, replace 'K' with 'e' in the 'From' field.
     
    Samik Raychaudhuri, Oct 16, 2004
    #4
    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. Martin Nilsson

    Assign program result or die

    Martin Nilsson, Jul 15, 2004, in forum: Perl
    Replies:
    1
    Views:
    523
    J├╝rgen Exner
    Jul 15, 2004
  2. daniel kaplan

    die question

    daniel kaplan, Sep 14, 2004, in forum: Perl
    Replies:
    2
    Views:
    530
    Sherm Pendley
    Sep 14, 2004
  3. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    446
    Natty Gur
    Jan 26, 2004
  4. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    460
    Alvin Bruney
    Jan 25, 2004
  5. dale zhang
    Replies:
    8
    Views:
    435
    Tintin
    Nov 30, 2004
Loading...

Share This Page