Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-06-23 10:17 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.