in reply to Re^3: nodelocked vs floating
in thread nodelocked vs floating
Thanks Ken. I have changed it like this and its working. I am using strawberry version.
for my $license (sort grep /^Node/, keys %{$hash{$product}})
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: nodelocked vs floating
by kcott (Archbishop) on Nov 24, 2018 at 06:41 UTC | |
"Thanks Ken." You're welcome. "I am using strawberry version." Strawberry provides many versions of Perl. It's the version of Perl that was important here. You can find that with the "perl -v" command. As an example, you can see that I'm currently using version 5.28:
Which means I can write:
— Ken | [reply] [d/l] [select] |
by 1nickt (Canon) on Nov 24, 2018 at 14:38 UTC | |
G'day Ken, Can you please share for the genuinely curious what you find advantageous about writing: vs. either of both of which are shorter and show the eye with the first character, rather than the penultimate, what the product is going to be?
The way forward always starts with a minimal test.
| [reply] [d/l] [select] |
by kcott (Archbishop) on Nov 25, 2018 at 07:16 UTC | |
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 | [reply] [d/l] [select] |