That is a very well written response. A definate ++.

Thanks

References are the Perl abstraction of pointers. That is not to say that references are pointers (They most certainly are not) but to say that you can usually think of them as such.

This is a statement I hear a lot, and I just don't get it. While references certainly _ARE_ Perl's abstraction of pointers, the use of them is so different that the comparison isn't really worth making. Pointers can be manipulated, references can't. (You noted that). If I can't do pointer operations on a reference, why pull in all the pointer baggage (While learning pointers wasn't conceptually hard for me, in practice they were the hardest CS concept for me to get working)

I think you under-sell the power of references by just saying that they are a way to nest data structures.

Okay, guilty as charged.

But you can de-reference it later. Or pass it to a subroutine, or store a collection of arrays in a hash by storing their references (but don't try to use references as hash keys... Perl converts them to a string for you, but won't reverse the process.)

All true. So how is the following as a short description (basically saying what you said without bringing in pointers):

"References are scalars that refer to a perl data structure. They can be de-referenced, which gives you the data structure. Because Perl data structures are normally "flat" (An array element or hash value can only be scalar), this allows you to creat nested data structures. Because perl subroutines are passed 1 list of parameters, it allows you to call a subroutine with multiple arrays, hashes, and even references to other subroutines. References are the backbone of modules, which change perl from a good scripting language into a powerful programming language."


In reply to RE: RE: Re: Is this a hash? or what? by swiftone
in thread Is this a hash? or what? by Zo

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.