Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perlop: mention why 'print !!0' doesn't #7747

Closed
p5pRT opened this issue Jan 11, 2005 · 21 comments
Closed

perlop: mention why 'print !!0' doesn't #7747

p5pRT opened this issue Jan 11, 2005 · 21 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 11, 2005

Migrated from rt.perl.org#33765 (status was 'resolved')

Searchable as RT33765$

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2005

From @jidanni

On perlop, perhaps add an explanation of why
$ perl -e 'print !!0'
prints nothing.

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2005

From @smpeters

On Tue, Jan 11, 2005 at 10​:22​:20PM -0000, Dan Jacobson wrote​:

# New Ticket Created by Dan Jacobson
# Please include the string​: [perl #33765]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=33765 >

On perlop, perhaps add an explanation of why
$ perl -e 'print !!0'
prints nothing.

perl -e 'print !!0'
perl -e 'print mutt0'

It prints something for me.

Steve Peters
steve@​fisharerojo.org

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2005

From @iabyn

On Tue, Jan 11, 2005 at 10​:22​:20PM -0000, Dan Jacobson wrote​:

On perlop, perhaps add an explanation of why
$ perl -e 'print !!0'
prints nothing.

Are you specicifally concerned with any peculairies of a double !!, or
just confused as to what perl returns as a FALSE value, ie would
you consider explaining the result of !1 to be just as useful?

--
"I do not resent critisism, even when, for the sake of emphasis,
it parts for the time with reality".
  -- Winston Churchill, House of Commons, 22nd Jan 1941.

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2005

From @tamias

On Tue, Jan 11, 2005 at 05​:06​:36PM -0600, Steve Peters wrote​:

On Tue, Jan 11, 2005 at 10​:22​:20PM -0000, Dan Jacobson wrote​:

# New Ticket Created by Dan Jacobson
# Please include the string​: [perl #33765]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=33765 >

On perlop, perhaps add an explanation of why
$ perl -e 'print !!0'
prints nothing.

perl -e 'print !!0'
perl -e 'print mutt0'

It prints something for me.

That's your shell expanding the exclamation marks, silly. Try bash
instead.

C<print !!0> prints nothing because the false value returned by logical
operators stringifies to the empty string.

Ronald

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2005

From @nwc10

On Tue, Jan 11, 2005 at 05​:06​:36PM -0600, Steve Peters wrote​:

perl -e 'print !!0'
perl -e 'print mutt0'

It prints something for me.

I do not think that you are using the same operating system (or at least
the same family of shell) as he is using :-)

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Jan 14, 2005

From @jidanni

D> C<print !!0> prints nothing because the false value returned by logical
D> operators stringifies to the empty string.

OK, mention something like that on perlop then, as beginners can't
figure out what went wrong with "print 0, !0, !!0".

@p5pRT
Copy link
Author

p5pRT commented Jan 15, 2005

From @samv

Dan Jacobson wrote​:

D> C<print !!0> prints nothing because the false value returned by logical
D> operators stringifies to the empty string.

OK, mention something like that on perlop then, as beginners can't
figure out what went wrong with "print 0, !0, !!0".

Dan,

I highly recommend _Programming Perl, 3rd edition_. The first few
chapters have a very concise description of the syntax of basic Perl,
along with some Perl "attitude" that will help you get past these
teething problems into using Perl whole-heartedly.

You seem to be disputing things that most people on the list would
hold up as key reasons to *like* Perl :-). It's not supposed to never
surprise you. It's supposed to be quirky and fun to use. It's supposed
to have character, how else can you expect to enjoy a lifetime of
programming it?

If you want consistent, predictable and boring, the python camp is
over there ---->

Sam

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2005

From @jidanni

D> I highly recommend _Programming Perl, 3rd edition_.

I'm located far away so getting more books are inconvenient. Anyways I
always need the answer "now" and I'm offline, and I hope to find it
within the Debian basic packages I have installed.

Though I'm not it the lunar lander, one hopes that the basic included
documentation would cover these missed points, with no need to check
websites or books for the answer.

Anyway, where ! is described, it seems reasonable to mention what its
results will look like when print()ed...

D> If you want consistent, predictable and boring, the python camp is

Hard to mash into one-liners for use in Makefiles.

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2005

From @iabyn

On Tue, Jan 18, 2005 at 03​:52​:18AM +0800, Dan Jacobson wrote​:

I'm located far away so getting more books are inconvenient. Anyways I
always need the answer "now" and I'm offline, and I hope to find it
within the Debian basic packages I have installed.

Okay, I'm going to be rude (again).

Please go away.

Please stop using the perlbug system for logging documentation enhancement
requests. Your concept of what should be in the Perl man pages clearly
differs from the majority of the people who are prepared to make changes
to them. That's a shame, but it's something you'll just have to live with.

I have better things to do with my time than replying to this crap.

Dave.

--
Thank God I'm an atheist.....

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2005

From @smpeters

[davem@​iabyn.com - Mon Jan 17 16​:33​:47 2005]​:

On Tue, Jan 18, 2005 at 03​:52​:18AM +0800, Dan Jacobson wrote​:

I'm located far away so getting more books are inconvenient. Anyways I
always need the answer "now" and I'm offline, and I hope to find it
within the Debian basic packages I have installed.

Okay, I'm going to be rude (again).

Please go away.

Please stop using the perlbug system for logging documentation enhancement
requests. Your concept of what should be in the Perl man pages clearly
differs from the majority of the people who are prepared to make changes
to them. That's a shame, but it's something you'll just have to live with.

I have better things to do with my time than replying to this crap.

Dave.

While I agree that an explanation of why "print !!0" doesn't work isn't needed (take a look at
Devel​::Peek. It's your friend!), I was unable to find actual documentation as to what values
actually evaluate to TRUE or FALSE in Perl. There is some pasing references to "", 0 and 1 in
perlop.pod. perlfaq4 deals with hashes. The rest, as I've painfully learned in the past, are
undocumented and a common source of bugs for beginners.

I've got a start on an explanation of what is TRUE or FALSE in Perl. My question is should it
go.

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2005

From @tamias

On Tue, Feb 01, 2005 at 05​:34​:18PM -0000, Steve Peters via RT wrote​:

While I agree that an explanation of why "print !!0" doesn't work isn't
needed (take a look at Devel​::Peek. It's your friend!), I was unable to
find actual documentation as to what values actually evaluate to TRUE or
FALSE in Perl. There is some pasing references to "", 0 and 1 in
perlop.pod. perlfaq4 deals with hashes. The rest, as I've painfully
learned in the past, are undocumented and a common source of bugs for
beginners.

perldoc perlsyn​:

  Truth and Falsehood

  The number 0, the strings '0' and '', the empty list "()", and "undef"
  are all false in a boolean context. All other values are true.

Is that sufficient? I'm not sure what you mean by "the rest".

Ronald

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2005

From @pjcj

On Tue, Feb 01, 2005 at 05​:34​:18PM -0000, Steve Peters via RT wrote​:

While I agree that an explanation of why "print !!0" doesn't work isn't needed (take a look at
Devel​::Peek. It's your friend!), I was unable to find actual documentation as to what values
actually evaluate to TRUE or FALSE in Perl. There is some pasing references to "", 0 and 1 in
perlop.pod. perlfaq4 deals with hashes. The rest, as I've painfully learned in the past, are
undocumented and a common source of bugs for beginners.

I've got a start on an explanation of what is TRUE or FALSE in Perl. My question is should it
go.

There's a short section entitled "Truth and Falsehood" in perlsyn that's
been there since 5.8.2. Did you just miss it, or do you think it needs
to be expanded on?

--
Paul Johnson - paul@​pjcj.net
http​://www.pjcj.net

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2005

From @nwc10

On Tue, Feb 01, 2005 at 12​:41​:27PM -0500, Ronald J Kimball wrote​:

On Tue, Feb 01, 2005 at 05​:34​:18PM -0000, Steve Peters via RT wrote​:

While I agree that an explanation of why "print !!0" doesn't work isn't
needed (take a look at Devel​::Peek. It's your friend!), I was unable to
find actual documentation as to what values actually evaluate to TRUE or
FALSE in Perl. There is some pasing references to "", 0 and 1 in
perlop.pod. perlfaq4 deals with hashes. The rest, as I've painfully
learned in the past, are undocumented and a common source of bugs for
beginners.

perldoc perlsyn​:

Truth and Falsehood

The number 0, the strings '0' and '', the empty list "()", and "undef"
are all false in a boolean context. All other values are true.

Is that sufficient? I'm not sure what you mean by "the rest".

The fact that the value returned for "false" is the string "", but the
number 0​:

$ perl -wle 'print ">$_< ", $_ + 0 foreach 1==1, 1!=1'

1< 1
< 0

And note that it's a dual value - it's not actually a regular empty string​:

$ perl -wle 'print ">$_< ", $_ + 0 foreach "1", ""'

1< 1
Argument "" isn't numeric in addition (+) at -e line 1.
< 0

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented May 11, 2005

From @smpeters

[nicholas - Tue Feb 01 09​:59​:22 2005]​:

On Tue, Feb 01, 2005 at 12​:41​:27PM -0500, Ronald J Kimball wrote​:

On Tue, Feb 01, 2005 at 05​:34​:18PM -0000, Steve Peters via RT wrote​:

While I agree that an explanation of why "print !!0" doesn't work
isn't
needed (take a look at Devel​::Peek. It's your friend!), I was
unable to
find actual documentation as to what values actually evaluate to
TRUE or
FALSE in Perl. There is some pasing references to "", 0 and 1 in
perlop.pod. perlfaq4 deals with hashes. The rest, as I've painfully
learned in the past, are undocumented and a common source of bugs for
beginners.

perldoc perlsyn​:

Truth and Falsehood

The number 0, the strings '0' and '', the empty list "()", and "undef"
are all false in a boolean context. All other values are true.

Is that sufficient? I'm not sure what you mean by "the rest".

The fact that the value returned for "false" is the string "", but the
number 0​:

$ perl -wle 'print ">$_< ", $_ + 0 foreach 1==1, 1!=1'

1< 1
< 0

And note that it's a dual value - it's not actually a regular empty
string​:

$ perl -wle 'print ">$_< ", $_ + 0 foreach "1", ""'

1< 1
Argument "" isn't numeric in addition (+) at -e line 1.
< 0

Nicholas Clark

The following patch should clear up this special false value.

Inline Patch
--- perlsyn.pod.old     Fri Oct 10 15:20:53 2003
+++ perlsyn.pod Wed May 11 11:56:47 2005
@@ -105,6 +105,9 @@

 The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
 C<undef> are all false in a boolean context. All other values are true.
+Negation of a true value by C<!> or C<not> returns a special false value.
+When evaluated as a string it is treated as C<''>, but as a number, it
+is treated as 0.

 =head2 Statement Modifiers

@p5pRT
Copy link
Author

p5pRT commented May 11, 2005

From @iabyn

On Wed, May 11, 2005 at 04​:58​:22PM -0000, Steve Peters via RT wrote​:

The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
C<undef> are all false in a boolean context. All other values are true.
+Negation of a true value by C<!> or C<not> returns a special false value.
+When evaluated as a string it is treated as C<''>, but as a number, it
+is treated as 0.

of course, it's not just '!', several ops have the ability to return the
dual-valued false., such as == and !=.

We really need a separate paragrah at the top of perlop describing the
'false' value in perl.

--
"Emacs isn't a bad OS once you get used to it.
It just lacks a decent editor."

@p5pRT
Copy link
Author

p5pRT commented Jun 9, 2006

From @smpeters

[davem@​iabyn.com - Wed May 11 10​:22​:53 2005]​:

On Wed, May 11, 2005 at 04​:58​:22PM -0000, Steve Peters via RT wrote​:

The number 0, the strings C<'0'> and C<''>, the empty list C<()>, and
C<undef> are all false in a boolean context. All other values are true.
+Negation of a true value by C<!> or C<not> returns a special false
value.
+When evaluated as a string it is treated as C<''>, but as a number, it
+is treated as 0.

of course, it's not just '!', several ops have the ability to return the
dual-valued false., such as == and !=.

We really need a separate paragrah at the top of perlop describing the
'false' value in perl.

So, do we need a section that explains just the false value or one that
explains the values returned from boolean ops in general?

@p5pRT
Copy link
Author

p5pRT commented Jun 9, 2006

From @iabyn

On Fri, Jun 09, 2006 at 01​:03​:29PM -0700, Steve Peters via RT wrote​:

[davem@​iabyn.com - Wed May 11 10​:22​:53 2005]​:
of course, it's not just '!', several ops have the ability to return the
dual-valued false., such as == and !=.

We really need a separate paragrah at the top of perlop describing the
'false' value in perl.

So, do we need a section that explains just the false value or one that
explains the values returned from boolean ops in general?

The latter I think.

--
"Emacs isn't a bad OS once you get used to it.
It just lacks a decent editor."

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2012

From @doy

This was done as part of 1ca345e. perlop now contains​:

  Perl operators that return true or false generally return values
  that can be safely used as numbers. For example, the relational
  operators in this section and the equality operators in the next
  one return 1 for true and a special version of the defined empty
  string, "", which counts as a zero but is exempt from warnings
  about improper numeric conversions, just as "0 but true" is.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2012

From [Unknown Contact. See original ticket]

This was done as part of 1ca345e. perlop now contains​:

  Perl operators that return true or false generally return values
  that can be safely used as numbers. For example, the relational
  operators in this section and the equality operators in the next
  one return 1 for true and a special version of the defined empty
  string, "", which counts as a zero but is exempt from warnings
  about improper numeric conversions, just as "0 but true" is.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2012

@doy - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant