G'day Bod,

It hadn't occurred to me when reading earlier posts referring to "old syntax", but your use of "modern syntax" made me wonder how much older $$hashref{key} was compared to $hashref->{key}.

The oldest Perl version available via the online "Perldoc Browser" is for "Perl 5.005". Poking around in various parts of that (perlop, perldsc, and others) I see both forms being used without any mention of one being newer. I'm happy to be proven wrong, but I rather suspect that both have been available since Perl 5.000.

Without the arrow (dereferencing) operator, it's easy to make mistakes, especially with complex data structures. This is discussed in "5.005: perlref: Using References"; this information is retained in "5.36.1: perlref: Using References".

Except in the simplest of cases, I'll always prefer the $hashref->{key} form, as I find it both easier to read and less error-prone. I can't think of any situation where the $$hashref{key} form is "required".

In closing, it's probably worth noting "Postfix Dereference Syntax" and "Postfix Reference Slicing". These are newer syntaxes. I prefer them; I acknowledge that others don't. There's an example of the former in my reply to the OP.

— Ken


In reply to Re^3: Reading session data by kcott
in thread Reading session data by PeterKaagman

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.