develooper Front page | perl.perl5.porters | Postings from February 2000

where did the EXPR1 if EXPR2 documentation go?

Thread Next
From:
Jeff Pinyan
Date:
February 27, 2000 22:37
Subject:
where did the EXPR1 if EXPR2 documentation go?
Message ID:
Pine.GSO.4.21.0002280131460.21801-100000@crusoe.crusoe.net
I believe the Camel book says that

  EXPR1 if EXPR2;

is synonymous with:

  EXPR2 && EXPR1;

And that

  EXPR1 unless EXPR2;

is synonymous with:

  EXPR2 || EXPR1;

Well, I can't find this in perlsyn (or anywhere else).  And I've not yet
checked the Camel, but this is a SLIGHT untruth.

I can say:

  $foo = (this() || that());

but I can't say:

  $foo = (that() unless this());

The reason I'm asking about this is because I was recently given a poser
as to why:

  @array = (1,0,0,1,0);
  print scalar grep { 1 if !$_ } @array;
  print scalar grep { 1 unless $_ } @array;

printed TWO different numbers.  "Isn't unless $_ the same as if
!$_?"  Well, I had to convince them that the ``A if B'' is really ``B ||
A'', and it's not in the Perl docs, and I told them they had to believe
me. :)

-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy@pobox.com
http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About