in reply to Confused about typeglobs and references
First, Joe is talking about passing arguments to subroutines efficiently. That's the reason for passing them by reference. You pass in a reference, the subroutine gets a reference.
Secondly, there is the issue of accessing an array (or whatever) efficiently/conveniently, when you have a reference to it. The idea is that if you have an array-ref $a_ref, you would like to be able to access its contents as if it were not a reference but a regular array variable (e.g. @a).
The latter is achieved by assigning the reference to a typeglob.
Given
But you can access the contents of the anonymous array by giving it a name, i.e by associating it with an entry in the symbol table. That's what typeglobs are good for.$a_ref = [ ... ]; # you can: print $a_ref->[0];
By talking about this technique in conjunction with argument passing, it kind of obscures the essence of what's going on here.*a = $a_ref; # now you can: print $a[0];
PS - strict does not care if you use typeglobs. That is, saying
will not raise an exception.use strict; *foo = [];
|
|---|