Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: if statement question

by Anonymous Monk
on Dec 13, 2012 at 20:41 UTC ( [id://1008718]=note: print w/replies, xml ) Need Help??


in reply to if statement question

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: if statement question
by tobyink (Canon) on Dec 13, 2012 at 22:24 UTC

    "Obviously a check for "truth value" is not a desirable practice."

    Ultimately all if conditions check truth values.

    if ($foo) and if (defined $foo) have two different meanings. One is not "better" than the other. Don't use the former when you mean the latter, but don't use the latter when you mean the former.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^2: if statement question
by Anonymous Monk on Dec 13, 2012 at 21:23 UTC

    That seems to come from the Java school of thought. A check for a true value is perfectly fine and does not need to be explicit. Being explicit is just worthless clutter, doubly so in a strongly typed language like Java. (I feel like strangling someone every time I have to type if (obj == NULL))

    (It's good, though, to have a clue on what the variable contains. I generally reserve such shorthands for boolean 0/1 values and variables which I expect to carry either undef or a reference.)

Re^2: if statement question
by BillKSmith (Monsignor) on Dec 14, 2012 at 14:32 UTC

    There is nothing wrong with boolean variables in perl, it really helps the reader if they are given names such as "$is_found" instead of "$search".

    Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-23 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found