in reply to Removing duplicates in multi-dimensional arrays

Please forgive me, I am a novice at best.

No worries.

it doesn't seem to work on my data.

The problem here is that you haven't shown what your data is and you haven't shown in what way it "doesn't seem to work". This gives the people who want to help you very little to go on. An SSCCE would be ideal.

That said, if you are using an AoA as @rows then you will have trouble. Maybe all you need is:

@rows = do { my %seen; grep { !$seen{$_->[2]}++ } @rows };

But without any data to test on, who can say?

As for explaining the code, you are grepping an array for entries which don't match entries in a hash which you build up as you go along. This is the standard, simplest de-duplication technique (without resorting to modules) as outlined in the FAQ How can I remove duplicate elements from a list or array?.

Replies are listed 'Best First'.
Re^2: Removing duplicates in multi-dimensional arrays
by DamnitAddie (Novice) on Oct 03, 2018 at 14:04 UTC

    That actually worked. I apologize for not being more verbose with the data.

    In the examples that I played with, I was trying $_2 vs $_->2 and getting all blanks.

    I appreciate your reply.

      Your post is a little bit difficult to read because "$_2 vs $_->2" is rendered a bit confusingly without  <code> tags. Please see Writeup Formatting Tips and Markup in the Monastery. You've already employed code-tags to good effect in your OP; you only need to be more thorough in their use.

      As an aside: Do you understand the difference between $_[2] and $_->[2]?

      And please do read and follow the principles discussed in the SSCCE article.


      Give a man a fish:  <%-{-{-{-<