in reply to Re: unique elements in a Hash of Arrays?
in thread unique elements in a Hash of Arrays?

Great thanks,
can you also tell me how I can count the unique elements per key of the Hash of Arrays?
  • Comment on Re^2: unique elements in a Hash of Arrays?

Replies are listed 'Best First'.
Re^3: unique elements in a Hash of Arrays?
by AppleFritter (Vicar) on Jul 13, 2014 at 22:40 UTC

    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.)

      Thank you SO much :)
        *tips hat* You're welcome, glad to have been of help!