in reply to Re: Re: 2D arrays & mo' better blues
in thread 2D arrays & mo' better blues

updated update: update removed

from perldoc perldsc

@outtie = ( [ @alpha ] ) x @alpha; looks ok to me.

"Argument is futile - you will be ignorralated!"

Replies are listed 'Best First'.
Re(4): 2D arrays & mo' better blues
by danger (Priest) on Jun 06, 2001 at 20:14 UTC

    Yes, the [@array] construct builds an array ref with a copy of the array --- But, the code in question uses the x operator to replicate a list of those references, and they will all be the same reference. Witness:

    my @list = (3,2,1); my @refs = ([@list]) x @list; print "@refs\n"; __END__ which prints: ARRAY(0x80f3764) ARRAY(0x80f3764) ARRAY(0x80f3764)

    Those are not references to the original array, they are all references to the same anonymous array that holds a copy of the original.

Re: Re: Re: Re: 2D arrays & mo' better blues
by davorg (Chancellor) on Jun 06, 2001 at 20:11 UTC

    It's true that square brackets make a reference to a new copy of the array. But the multiplication operator then takes 26 copies of that reference.

    I was originally going to post the same solution, but before I did, I checked it in the debugger :)

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me