Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Removal of duplicated element in array.

by moritz (Cardinal)
on May 06, 2013 at 14:01 UTC ( #1032297=note: print w/replies, xml ) Need Help??

in reply to Removal of duplicated element in array.

How exactly does it not work? What exactly is in $1? What output do you expect? Are you aware that the code as-is splits on newline characters, which means that "duplicate items" actually mean "duplicate lines"?

If you want to deduplicate a list, I recommend List::MoreUtils::uniq.

Replies are listed 'Best First'.
Re^2: Removal of duplicated element in array.
by tty1x (Novice) on May 06, 2013 at 14:10 UTC
    $1 is essentially a list of email addresses.

      my %seen = map {$_=>1} <DATA>; use Data::Dumper; print Dumper \%seen; __DATA__
      If you care about the order of display then you can use this:
        print join "\n", sort{$a cmp $b} keys %seen;

      *Note: That was based on the assumption, that the original ORDER of data was inconsequential.
      Limbic~Region Thanks for pointing that out.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me
        If you care about the order of display then you can use this

        The code in the OP looked like it was preserving the original order - what you have posted loses that ordering and sorting ASCIIbetically after the fact isn't going to re-instate it unless it coincidentally was sorted that way in the first place.

        Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032297]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2016-10-26 18:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (345 votes). Check out past polls.