Re: evaluating assigning to a list in if( ) statement

2001-09-10 Thread Jeff 'japhy/Marillion' Pinyan

On Sep 10, Andrew Pimlott said:

On Tue, Sep 04, 2001 at 08:52:11AM -0400, Jeff 'japhy/Marillion' Pinyan wrote:
 And the difference is?  An array isn't the same as a list, but assigning
 to an array is the same as assigning to a list.

Consider the difference between

@a = (1, 2);

and

($a[0], $a[1], $a[2]) = (1, 2)

That is not the issue.  Assignment to an array is assignment to a list,
and behaves like a list assignment.  Just because it's a dynamically sized
list does not mean it's not a list.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **




Re: evaluating assigning to a list in if( ) statement

2001-09-04 Thread Jeff 'japhy/Marillion' Pinyan

On Sep 4, Newton, Philip said:

Hm, I beg to disagree -- that's an array assignment, not a list assignment.

And the difference is?  An array isn't the same as a list, but assigning
to an array is the same as assigning to a list.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **




Re: evaluating assigning to a list in if( ) statement

2001-09-03 Thread Ronald J Kimball

On Mon, Sep 03, 2001 at 09:35:13PM -0400, Lev Selector wrote:
 # Folks, just a note.
 # I thought that the 
 #if (EXPR)
 # is supposed to evaluate the EXPR in scalar context, right?
 # Well, it does so in most cases
 # Except when you do an assignment to a list, when 
 # instead of evaluating a list as its last element - it evaluates
 # the number of elements (like an array) (see Example_5 below).
 # This is probably what you would want to test (if list empty or not)
 # 
 # Any comments?

perldoc perldata:

   List assignment in a scalar context returns the number of
   elements produced by the expression on the right side of
   the assignment:

   $x = (($foo,$bar) = (3,2,1));   # set $x to 3, not 2
   $x = (($foo,$bar) = f());   # set $x to f()'s return count

   This is very handy when you want to do a list assignment
   in a Boolean context, because most list functions return a
   null list when finished, which when assigned produces a 0,
   which is interpreted as FALSE.


Ronald