in reply to Converting an Array Reference into an Array

Under the hood, an array reference and an array are the same thing. (There are just two hoods to look under with an array reference.) Your technique for turning an array reference into an array is workable and the proper way to do it, but you are paying the penalty of cloning the array because you're copying things.

There's really no good way to do what you're suggesting without cloning things, unless you want to be very sneaky and mess with typeglobs. I prefer this dereferencing syntax, though:

my $element = $PassedArrayRef->[ $index ];

Just for kicks, here's the typeglob/global syntax you really oughtn't use. (If you don't understand it, you're probably better off!)

local *notacopy; *notacopy = $PassedArrayRef; my $element = $notacopy[ $index ];

I can't think of a good reason to do that, though.

Replies are listed 'Best First'.
Re: Re: Converting an Array Reference into an Array
by NetWallah (Canon) on Mar 12, 2003 at 17:54 UTC
    Thanks for those insights. I just discovered a relevant discussion on what I was trying to understand - a reference to an array of arrays.

    I have discovered that the documentation in the "perllol manpage" is pretty good for this subject.

    Also, I consider the syntax of $ArrayRef->[$index] to meet my "Elegance" standards (Better than $$ArrayRef[$index]). The glob stuff seems cool too, but, without a full understanding of the implications, I'll treat it as dangerous and eschewable.

    Thanks for bestowing all the wisdom, and cleaning up my message format. (I'm still learning, and hope to do that for the rest of my life).