Okay, I've seen and used this a hundred times, but I have to come clean...I have no idea what is going on "under the hood" with this:
my %counts; my @uniqueIPs = grep !$counts{$_}++, @ipAddresses;
I'd like to have someone explain it to me in a sentence or two. But let me take a stab at it first:
1. The first element in the list @ipAddresses becomes the first key in the hash %counts.
2. And because the first element of @ipAddresses ($_) is not equal to the first element of @uniqueIPs (mainly because it's empty), the first element of @ipAddresses ($_) is "pushed" onto @uniqueIPs.
3. HERE'S WHERE I GET LOST: What is incrementing that value? The fact that it satisfies the condition of not matching, therefore being true? And let's say the next element in @ipAddresses is the same as the first, and because it IS equal to the first element of @uniqueIPs it is *not* pushed. QUESTION: Why would the value of that first key get incremented.
So, is the condition asking "if it is not equal then increment it?"
What am I not getting? Thanks.
In reply to Re^2: Counting unique instances from Array Sort: explanation needed
by bradcathey
in thread Counting unique instances from Array Sort
by ewhitt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |