in reply to Help with references

$HASH{2}, for example, is an array reference. For any array reference, you can get a copy of the array by surrounding the reference by @{...}. You can get individual elements by putting ->[$index] after the reference. So..
my @things = @{ $HASH{2} }; ## @things is now a copy of @ARRAY2 my $foo = $HASH{2}->[1]; ## $foo is now $ARRAY2[1]
Also, when the -> dereferencing operator is in between subscripts (as it is here, between a hash and array subscript), it is optional. So the 2nd example would usually be written as $HASH{2}[1].

blokhead

Replies are listed 'Best First'.
Re: Re: Help with references
by pg (Canon) on Oct 23, 2003 at 02:45 UTC

    I understand that blokhead included the syntax to copy array for completeness, but it sounds like you are new to Perl. So I think it is worth to tell you that, it is generally not a good idea to copy the entire array, as it hurts performance.

    To get hold of each individual array, you only need the array ref, which you can get by saying:

    $hash{1}