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

Reply via email to