in reply to Counting matches and removing duplicates

After reading the file line by line into an array called @LIST, you would then remove the duplicates like this:

my %seen;
grep !$seen{$_}++, @LIST;

and then sort the list by names:

sort {uc($a) cmp uc($b)} @LIST;

( Note: I copied the first code snippet from https://stackoverflow.com/questions/7651/how-do-i-remove-duplicate-items-from-an-array-in-perl )

  • Comment on Re: Counting matches and removing duplicates

Replies are listed 'Best First'.
Re^2: Counting matches and removing duplicates
by hippo (Archbishop) on Nov 15, 2024 at 19:07 UTC

    You have advocated using grep in a void context. Please explain why.


    🦛

      he overlooked that the snippet was the inside of a subroutine, where the grep result would serve as the return value.
      But at least he gave a credible citation (although he could've cited should've read the PerlFAQ 4 section directly), so I ++ anyway.
Re^2: Counting matches and removing duplicates
by jo37 (Curate) on Nov 15, 2024 at 19:02 UTC

    Ever heard of fc?

    Greetings,
    🐻

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

      news to me!!!!! thanks for this.