[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] A Perl curiosity



Yitzchak Scott-Thoennes wrote:
> 
> Someone pointed this out on p5p recently:
> 
> #!perl -wl
> @array = (1,0,0,1,0);
> print scalar grep { 1 if !$_ } @array;
> print scalar grep { 1 unless $_ } @array;
> 
> Lines 3 and 4 produce different output, for reasons that should be
> apparent, given some thought.
> 
> I guess that's what Perl gets for blurring C's iron-clad distinction
> between statement and expression.


Is there a problem?  What _should_ unless return?

Unless is like a backwards or, so the falling-through of or semantics
continues


contrast:
 perl -wle 'print STDOUT eval {"w" unless "g"}'
 perl -wle 'print STDOUT eval {"w" unless 0}'
 

A unless B is equivalent to B or A




___________________________________________________________________
                           David Nicol 816.235.1187 nicold@umkc.edu
              eating cheese on toast, peering through the snow, etc

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe