in reply to Re: saving nested arrays in a hash
in thread saving nested arrays in a hash

thanks! it works now. so what's the technical difference between $ref=\@something and $ref =[@something] ? sorry about the faulty example code... it's not copied from the actual script.. I just typed it here with the silly mistakes included

my bad.

:)

Replies are listed 'Best First'.
Re^3: saving nested arrays in a hash
by jethro (Monsignor) on Aug 26, 2010 at 18:01 UTC

    Lets say @something is at memory location 0x12345

    $ref= \@something; print $ref; # would print 0x12345, right? $ref2= \@something; print $ref2; # would print 0x12345 as well

    Obvious, right? You take a reference to the array, it will be always the same. Now the other case:

    $ref= [ @something ]; # would be the same as $ref= \( @something ); # if that syntax where possible, or my @x= ( @something ); # with correct syntax $ref= \@x;

    i.e. [] is just () with an additional reference-taking. And by doing ( @array ) you are creating a new array (at a new memory address) with the contents of @array filled in

    ( @array ) is not the same as @array. This is obvious when you look at @newarray= ( @array1, @array2 );. It can't be the same

Re^3: saving nested arrays in a hash
by TomDLux (Vicar) on Aug 26, 2010 at 17:38 UTC
    $ref1 = \@arr; $ref2 = \@arr;

    The two references both point to the same underlying data structure.

    $ref1 = [ @arr ]; $ref2 = [ @arr ];

    The two references each point to different anonymous arrays, which have the same values as @arr, but are different structures.

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.