Multiline die

S

Samik Raychaudhuri

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

A. Sinan Unur

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

Paul Lalli

Samik Raychaudhuri said:
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
 
S

Samik Raychaudhuri

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.

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




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.
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top