Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Truth and Falsehood

by haukex (Archbishop)
on Aug 18, 2019 at 06:46 UTC ( [id://11104635]=note: print w/replies, xml ) Need Help??


in reply to Re: Truth and Falsehood
in thread Truth and Falsehood

While I know that you did not label this "[RFC]", this looks like a good draft for a brief tutorial.

The intent was a little different, as I mentioned at the very bottom of the node: There used to be a section "Truth and Falsehood" in perlsyn that was nice and short, and easy to link to whenever someone's question touched on Perl's concept of true/false, but that section was merged into a much longer block of text in perldata, which IMHO makes it harder to provide a link to people who just want to know about that one topic. (The title is such that it's easy to link to as [Truth and Falsehood].) So I want to keep the main point of the node focused on just true/false, hence I tried to separate out the "Related Topics" so that the top is just a "TL;DR".

As currently written, this neglects $#array.

Yes, that's a good point, I'll add a brief mention of it, thanks. IMHO, the more detailed description you wrote starts getting a little off-topic to the main point of the node, so I'll keep it a little shorter.

The exists and defined tests also apply to array indexes

Not entirely; from exists:

WARNING: Calling exists on array values is strongly discouraged. The notion of deleting or checking the existence of Perl array elements is not conceptually coherent, and can lead to surprising behavior.
would it be better to say that length returns undef without producing a warning?

Yes, good point, thanks!

Replies are listed 'Best First'.
Re^3: Truth and Falsehood
by jcb (Parson) on Aug 18, 2019 at 07:10 UTC
    the more detailed description you wrote starts getting a little off-topic

    Fair enough, and the link to the reference manual makes up for trimming it.

    [for exists on arrays]

    The tests apply, even though the results can be surprising, mostly due to the fact that Perl's arrays have a contiguous range of index values. I suspect that exists $array[$i] is equivalent to $i <= $#array. If not, then that is really surprising and probably better left "under the rug". :-)

Re^3: Truth and Falsehood
by Anonymous Monk on Nov 01, 2019 at 23:53 UTC
    perl -M5.27.6 -e '$_=`perldoc -Tt perldata`;s/.*(A scalar.*?way).*/$1. +/s;say'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-23 06:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found