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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |