Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

---
demerphq


In reply to Re: Introduction to anonymous arrays and hashes by demerphq
in thread Introduction to anonymous arrays and hashes by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2023-01-29 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?