in reply to Re: Getting different anonymous arrays
in thread Getting different anonymous arrays

This is just a freeze/thaw way of getting back a structure which points at the same arrayref. If you built it like this:

%array = ( 'a' => ['a','b','c','d'], 'b' => ['a','b','c','d'], 'c' => ['a','b','c','d'], 'd' => ['a','b','c','d'] );

you would have four different anonymous arrays, not four refencences to the same array, as the original code created.

Not sure if this answered your question, or if I even understood it, but there you go :).

Replies are listed 'Best First'.
Re^3: Getting different anonymous arrays
by flounder99 (Friar) on Sep 08, 2003 at 18:38 UTC
    I just thought it was weird that the anonymous array was definded as the value of the hash key 'c' and all the rest of the hash keys have a value of its reference. It seems to me that the hash key 'a' would have been defined first and the other keys would have the value of its reference. I guess it doesn't matter -- they all point to the same anonymous array reference.

    I see what happens. if I add this line to my original program:

    print join ",", keys %array;
    I get an output of:
    c,a,b,d
    So Data::Dumper must just take the first key it gets from keys point it to the anonymous array reference and then have the rest of the keys point to it. That makes sense. You learn something new every day.

    --

    flounder