|No such thing as a small change|
Re^2: Perl Best Practices for naming variablesby creamygoodness (Curate)
|on Aug 07, 2005 at 00:36 UTC||Need Help??|
Exactly right, that's what Damian recommends. There's obviously someone besides him who's made it work.
I suppose I've just solved the problem he's looking to address by never using identical identifiers for different purposes. What's the advantage to me for adding those extra four characters? Now I can use %option, @option, $option, and &option in the same scope and, uh, not get them mixed up? ;) On the flip side, what's the penalty for typing$items when you meant $items->? No more than a missing semi-colon, or other simple syntax error. Unless your program takes a long time to compile, no big deal: run, tweak, run, tweak...
I might not find this constraint so onerous if I hadn't produced a lot of code that goes up to 78 characters.
... (time passes while Marvin peruses book) ...
It looks like the answer is, for Perl 5.8.1 onwards, the Data::Alias module. The main situation where I'd need _ref is when pulling elements out of a large and complex object for manipulation in a method. Here's what I've been doing:
With the Data::Alias module, I can do this instead:
That's probably faster. It's sure cleaner. I like. And as a bonus, now when I use _ref, it will imply something useful -- like, "this is a giant array and I want to pass it by reference".
Tasty spinach, yo,