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

Re: [FWP] Testing list?



David H. Adler wrote:
> On Wed, Jan 05, 2000 at 07:21:21PM +0000, Peter Haworth wrote:
> > John Porter wrote:
> > > 
> > > Huh?  
> > >      ( $a, $b, @c ) ||= ( 1, 2, 3, 4, 5 );
> > > would be the same as
> > >      ( $a, $b, @c ) or
> > >      ( $a, $b, @c ) = ( 1, 2, 3, 4, 5 );
> > 
> > But ($a,$b,@c) is always true!
> 
> You might think so, but...

Well, I did before I tested it.

What's actually happening here is that the LHS is being evaluated in scalar
context, which means that it's the scalar value of @c which is being tested for
truth - $a and $b are evaluated, then thrown away.

So:
  @c=();
  print (($a,$b,@c) ? "true\n" : "not true\n");
  @c=(0);
  print (($a,$b,@c) ? "true\n" : "not true\n");
prints:
  not true
  true

So that's yet more semantics which this would change. I still say it's not
worth it.

-- 
	Peter Haworth	pmh@edison.ioppublishing.com
"Come to think of it, there are already a million monkeys on a
 million typewriters, and Usenet is NOTHING like Shakespeare."


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