Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 (Chancellor) 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]
[marto]: that is to say, to the best of my knowledge, they never did.
[marto]: they have a commercial product called perlapp
[mark4]: Do you h=know how I can get pp.exe? Is there a module I can install that includes this?
[marto]: I always found Strawberry Perl on windows to be a much better environment, made life much easier
[marto]: pp. install it like you would any other module
[marto]: it probably exists in one of the PPM repositories
[marto]: failing that see the README
[mark4]: I installed "PAR" from the ppm install window. pp.exe. did not show up.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2018-01-19 14:15 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (218 votes). Check out past polls.