in reply to Re^2: unique elements in a Hash of Arrays?
in thread unique elements in a Hash of Arrays?
Sure. uniq returns a list of unique elements, and lists evaluate to their number of elements in scalar context, so if you replace the line inside the foreach with e.g. this:
say "$_: ", scalar uniq @{ $HoA{$_} };
Then you'll get the number of unique items. (You could equally well assign to a variable for further processing, of course, and if you assign to a scalar, the explicit scalar won't be necessary, though it also won't hurt and may serve to make it a bit clearer what's going on.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: unique elements in a Hash of Arrays?
by Anonymous Monk on Jul 13, 2014 at 23:03 UTC | |
by AppleFritter (Vicar) on Jul 13, 2014 at 23:18 UTC |