some puzzles

Michael Fowler michael at shoebox.net
Tue Mar 20 17:04:38 CST 2001


On Tue, Mar 20, 2001 at 11:22:15AM -0800, Roxanne Reid-Bennett wrote:

I missed these examples, otherwise I would've commented on them in my
earlier email.

> 6. $var, $v2, $v3 = 10, 20, 30;  #$var is 10, $v2 is 10, $v3 is 10
> 7. $vx1, $vx2, $vx3 = (10, 20, 30);  #$vx1 is "" $vx2 is "" $vx3 is 30
> 8. ($v1, $v2, $v3) = (10, 20, 30);  #$v1 is 10 $v2 is 20 $v3 is 30
> 
> 8. makes sense to me, but 6 and 7 were not what I expected to see.

6 and 7 don't make sense, and in fact aren't what I see with various
versions of Perl.  What version of Perl are you using?

With 5.00405, 5.00503, and 5.6.0 I see the following:

Example 6:
    > perl -wle '$var, $v2, $v3 = 10, 20, 30; print "$var, $v2, $v3";'
    Useless use of a variable in void context at -e line 1.
    Useless use of a variable in void context at -e line 1.
    Useless use of a constant in void context at -e line 1.
    Useless use of a constant in void context at -e line 1.
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    , , 10

Which is what I expect.  $var and $v2 are being discarded, as are 20 and 30;
the only operation of substance is $v3 = 10.


Example 7:

    > perl -wle '$vx1, $vx2, $vx3 = (10, 20, 30); print "$vx1, $vx2, $vx3";'
    Useless use of a constant in void context at -e line 1.
    Useless use of a constant in void context at -e line 1.
    Useless use of a variable in void context at -e line 1.
    Useless use of a variable in void context at -e line 1.
    Use of uninitialized value at -e line 1.
    Use of uninitialized value at -e line 1.
    , , 30

(with minor changes in the warnings for 5.6.0)

$vx1 and $vx2 are being discarded, and the list (10, 20, 30) is being
evaluated in scalar context, yielding 30 and discarding 10 and 20.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
=================================================
Mailing list info:  If at any time you wish to (un|re)subscribe to
the list send the request to majordomo at hfb.pm.org.  All requests
should be in the body, and look like such
                  subscribe anchorage-pm-list
                  unsubscribe anchorage-pm-list



More information about the Anchorage-pm mailing list