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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A scalar value is interpreted as TRUE in the Boolean sense if it is not the null string or the number 0 (or its string equivalent, "0"). The Boolean context is just a special kind of scalar context where no conversion to a string or a number is ever performed. (see perldata)

I know what you mean by the null string, but not every one does, specially not the people who need a reference. Perl doesn't have the concept of null, and we avoid using the term null string, because it's not always clear what is meant by it, the empty string, or an undefined value.

Having said that, you only list three things that are false in boolean context: the empty string (null string), the number 0, and the string "0". But you left out the most important one: the undefined value. But there are more, here's a (hopefully) complete list:

  • The undefined value.
  • The number 0.
  • The empty string.
  • The string "0".
  • An empty array.
  • An empty hash.
  • Objects with appropriate overloaded boolean value.

When used as a number, undef is treated as 0; when used as a string, it is treated the empty string, ""; and when used as a reference that isn't being assigned to, it is treated as an error.

Well, there's also auto-vivification.

The while statement executes the block as long as the expression is true (does not evaluate to the null string "" or 0 or "0"). (see perlsyn)

I wonder why you mention while, but not for(;;) or until. Having said that, your statement is close, but not completely true. The block can also be exited with a last, return, goto, die or even a next LABEL_TO_OUTER_BLOCK statement. Furthermore, if the condition becomes false during execution of the block, the execution isn't stopped - checks are only done before entering the block. Finally, there's

do { ... } while (0);
which will execute the block at least once, even if the condition is never true.

In reply to Re: True or False? A Quick Reference Guide by Anonymous Monk
in thread True or False? A Quick Reference Guide by bobf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found