--- Peter Scott <[EMAIL PROTECTED]> wrote:
> At 09:35 AM 6/15/01 -0400, you wrote:
> >So why would you call a reference to an array instead of just
> calling the
> >array itself?
>
> Assuming your question doesn't contain some implication to the thread
> but it just a general question of why an arrayref is useful, why,
many
> reasons. For one, you can't construct a 2-dimensional array without
> one. Or pass multiple variable-length lists to a subroutine:
>
> interleave([qw(see useful can)], [qw(how this be)])
elaboration: $array[0] is whatever you put there, but if you say
$array[0][3] = 'foo';
then what you just put into $array[0] is a reference to an anonymous
array, into the 4th cell of which you put 'foo'.
As for passing "multiple variable-length lists to a subroutine", refs
are the only way to keep multiple lists from flattening out into one
when passing data to or from a function.
func(@a1,@a2);
sends one list, and func() can't tell where @a1 stops and @a2 starts.
But if you say
func(\@a1,\@a2);
Then your list consists of two scalars -- the references to the arrays,
which can then be dereferenced seperately. =o)
__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/