Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Multiline die

Reply
Thread Tools

Multiline die

 
 
Samik Raychaudhuri
Guest
Posts: n/a
 
      10-15-2004
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.
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-15-2004
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/cl...uidelines.html

Sinan.

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      10-15-2004
"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


 
Reply With Quote
 
Samik Raychaudhuri
Guest
Posts: n/a
 
      10-16-2004
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.
 
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
re: @Don postet euch den Film des Jahres " Die rache der Sith " in MVCD (028/110] - "Star Wars Episode 3 - Die Rache der Sith ( 1_2 MVCD ) ein @Don post.part28.rar" Marco Computer Support 0 05-22-2005 01:25 PM
Die IDE Die Lloyd Sheen ASP .Net 2 01-26-2004 04:59 AM
More Die IDE Die Lloyd Sheen ASP .Net 5 01-25-2004 02:34 PM
DVD Verdict reviews: DIE! DIE! MY DARLING!, LOOK! PLAYFUL PATTERNS AND SIMPLE SHAPES / GO! EXERCISE WITH THE TELETUBBIES, and more! DVD Verdict DVD Video 0 09-26-2003 09:02 AM
I want to be a hacker/nerd b4 I die. Ghost issues (now and after I die) O.Phooey Computer Support 4 07-05-2003 08:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57