in reply to Introduction to anonymous arrays and hashes
IMO the term "an anonymous X" is a term that is a bit of a distraction as it is often used as a synonym for "a reference to an X". Most times the fact that a given ref is truely anonymous is completely irrelevent to anything. In fact the only case I can think where the term means anything useful is referring to distinct notational styles of creation/declaration of the vars involved. Furthermore the fact that a given ref may be anonymous at one time does not mean that it will always be anonymous, and likewise the fact that a given ref is named at one does not mean that later on it wont be anonymous. Consider some of the examples below:
@list_of_refs=map { +{ $_ => 1 } } 1..10; @list_of_refs=map { my %hash=($_=>1); \%hash } 1..10; my $anon_array=[]; *now_its_not_anonymous=$anon_array; @now_its_not_anonymous=(1..10); print @{$anon_array}; our @foo=(1..10); my $ref=\@foo; { # the old @foo goes away now... local @foo=[]; print @$foo; print @$ref; }
Conclusion: the term anonymous really is only a useful distinction when considering creation/declaration notation:
my $ref_to_anon={ a=>1 }; my %named=(a=>1); my $ref_to_named=\%named; # realistically there is no way to tell which ref is to an anonymous a +rray
Outside of that there is no reason to use the expression as there are functionally no differences between a "reference to an array" and a "anonymous array". The latter can only be manipulated as the former. I supect the main reason people tend to use this term is brevity: if you need to describe the args to a subroutine and you want to say "reference to an array" then "anonymous array" can be an attractive alternative. Albeit a somewhat confusing one to someone who isn't aware there that really is no way for a peice of code to know if a given reference is to an anonymous or named array. This is especially true as that status may be determined at run time via dynamic scoping.
|
|---|