Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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.


Comment on Re: Removal of duplicated element in array.
Download Code
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.

    dddd@fgg.com
    cccc@fgg.com
    eeee@fgg.com
    dddd@fgg.com
    

      my %seen = map {$_=>1} <DATA>; use Data::Dumper; print Dumper \%seen; __DATA__ dddd@fgg.com cccc@fgg.com eeee@fgg.com dddd@fgg.com
      *UPDATE:
      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
        2teez,
        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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2014-07-26 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls