Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Being more Assert-ive with Perl

by muba (Priest)
on Sep 23, 2004 at 15:51 UTC ( [id://393235]=note: print w/replies, xml ) Need Help??


in reply to Being more Assert-ive with Perl

Nice :) It is readable indeed, but it could even be better. This is just a small tip, I do not want to offend you in any way, but I think
# warn the user of the wrong input and return # false, leaving the calling routine dealing # with things (defined($coin) && $coin == 25) || (warn("You must insert 25 cents"), +return 0);
is better written as
# warn the user of the wrong input and return # false, leaving the calling routine dealing # with things (defined($coin) && $coin == 25) || return do {warn("You must insert 25 + cents"); 0};
IMHO, that would even be more readable




"2b"||!"2b";$$_="the question"

Replies are listed 'Best First'.
Re^2: Being more Assert-ive with Perl
by stvn (Monsignor) on Sep 23, 2004 at 16:00 UTC
    MUBA,

    No offense taken at all. I usually use die or throw an exception object. So the examples with warn and such are ones I made up when writing this. I am sure they could be improved, and I agree the do does make it more readable.

    -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://393235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-26 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found