--- Robb Wagoner <[EMAIL PROTECTED]> wrote:
> I have a two dimensional array where each element consists of a
> reference to an anonymous array.
>
> push(@array,[$var1,$var2,$var3]);
That's pretty much the way all multidimensional arrays (and hashes)
work in Perl.
> When I pass a reference to the array in a subroutine:
>
> some_sub(\@array);
>
> What is the proper way to dereference the array with in the
> subroutine?
"Proper"? Hey, TMTOWTDI, but here's a couple that are pretty standard.
1) the probably better way:
sub some_sub {
my $ray = shift; # $ray is now the array reference
print $ray->[0][0]; # this *IS* $array[0][0]
# . . . .
}
2) the unrecommended-but-good-to-know way:
sub some_sub {
local *ray = shift; # *ray receives the reference
print $ray[0][0]; # this *IS* $array[0][0]
# . . . .
}
Since the glob *ray receives the reference into the appropriate
subsection, the array reference means @ray *is* @array.
Local is better avoided unless you have a really good reason to use it,
though (such as when you can't do the same thing with my(), which isn't
so in this case.)
Um, you want an example? Ok.... you can't my() the global special
variables, such as $_ -- if you use them in a subroutine, localize them
so that you don't blast their global content, in case something in a
line below the function call expects it to be the same as it was above
it. Better code? Don't write code with that assumption.... =o)
Sorry to blather. Was having fun, lol....
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]