Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^7: nodelocked vs floatingby kcott (Archbishop) |
on Nov 25, 2018 at 07:16 UTC ( [id://1226281]=note: print w/replies, xml ) | Need Help?? |
The example I showed with $href->%* was highly simplistic. It was intended to show that, with 5.28, I could use the new syntax and didn't need to include a 'use feature' statement. When dealing with simple references, I would typically use @$aref, %$href, and so on, rather than $aref->@*, $href->%*, etc. When working with complex data structures, that simple reference becomes a series of keys and indexes read from left-to-right. Adding a postfix dereference continues that left-to-right progression: you don't need to scan back to the beginning of the expression to determine what dereferencing is being used. Consider these two:
Of course, they're only short, example variable names. In production code, I'd be using meaningful variable names:
Here, the benefit of not having to scan back to the beginning of the expression becomes more obvious. Except for the simple references, like %$href, there's only one additional character when using the postfix syntax: I wouldn't consider that to be a reason to use, or not use, it. When whatever is being dereferenced is more complicated than a simple reference, I would recommend adding the braces (e.g. prefer @{$complex_ref} over @$complex_ref). Even when @$complex_ref seems completely transparent to the author, it might easily be less obvious to the next maintainer. Using postfix dereferencing, in the contexts I've described above, is my personal preference for the reasons given. I would recommend its use to others for the same reasons. I certainly wouldn't suggest anyone must use it. In "Re^3: nodelocked vs floating", I did point out that it took me "a little while to get used to": if you're considering giving it a try, you might also want to give it a little while also. Finally, some practical notes on usage:
— Ken
In Section
Seekers of Perl Wisdom
|
|