From the POD for Perl 5.14 I noticed the following in the documentation of each:

Starting with Perl 5.14, each can take a scalar EXPR, which must hold reference to an unblessed hash or array. The argument will be dereferenced automatically. This aspect of each is considered highly experimental. The exact behaviour may change in a future version of Perl.

while (($key,$value) = each $hashref) { ... }

My first reaction to reading that was why would we want to make a change that makes it harder to spot an error? Previously, each $hashref, or each \%hash, or even each { 'this' => 1 } would have been errors, and perl would tell you that. Now, they're legitimate, and Perl accepts them. But seeing such constructs in code could imply that the programmer has lost track of data-structure depth (though it might also be argued that we shouldn't care). When I type each %{ $hashref };, I know where I am in a datastructure. If we relax the requirements, we give up some of the visual syntactic cues.

It could be argued that the new relaxed syntax improves the ability to traverse datastructures without worrying about where we are in the structure of arbitrary depth.

I'm sure that a great deal of discussion goes into this sort of change, and I was just wondering if anyone can provide more insight as to the advantages of the newly relaxed syntax for each.


Dave


In reply to New behavior of 'each' with respect to references by davido

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.