Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: array assignment with list operator , no parenthesis

by Random_Walk (Prior)
on May 14, 2007 at 14:04 UTC ( #615308=note: print w/replies, xml ) Need Help??

in reply to array assignment with list operator , no parenthesis

You are not copying an array into your array. You are putting in the result of the operation 7,2,3 which is 7 @one = 7,2,3 which due to precedence is evaluated as (my @one = 7),2,3 as previously explained in this thread. To get the array I think you want in there:

use strict; use warnings; use strict; my @one = (7,2,3); print "@one\n"; Output :- 7 2 3


Pereant, qui ante nos nostra dixerunt!


shmem pointed out my sloppy summary of this problem. I was concentrating on what I thought he wanted to achieve and lost sight of the true explanation.

Replies are listed 'Best First'.
Re^2: array assignment with list operator , no parenthesis
by shmem (Canon) on May 14, 2007 at 14:10 UTC
    You are putting the result of the operation 7,2,3 which is 7.

    No, it is not. Consider:

    perl -le 'sub foo { 7,2,3 } $foo = foo(); print $foo' 3

    It's a precedence problem as other posters pointed out.

    update Well, actually... the above example is misleading, since the comma operator is used in list context here - subroutines always return lists (if not declared with a single ($) as prototype, that is). And evaluating a list in scalar context gives its last element - which is just what the comma operator does ;-) A better example might be

    print not 1,0; print $/; __END__ 1

    The not operator gets the 0 and turns it to 1.


    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://615308]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2016-10-24 22:01 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (310 votes). Check out past polls.