Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Removal of duplicated element in array.

by 2teez (Priest)
on May 07, 2013 at 04:25 UTC ( #1032436=note: print w/ replies, xml ) Need Help??


in reply to Removal of duplicated element in array.

Hi tty1x,
A few snapshot observations and 2 'kobo' suggestion:

  • A number of solution previously given to you actually work, only that some may not preserve the order of data.
  • This does work for me, which is not far from your OP, except that I have to create the variable $match.
    use warnings; use strict; my $match = <<'EOF'; dddd@fgg.com cccc@fgg.com eeee@fgg.com dddd@fgg.com EOF my %seen; my @r; foreach my $v ( split /\n/, $match ) { unless ( $seen{$v}++ ) { push @r, $v; } } $" = "\n"; print "@r";
  • Please, as much as possible try not to use the variable $a, since function sort uses it
Tested this out on codepad an online compiler/interpreter.

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


Comment on Re: Removal of duplicated element in array.
Download Code
Replies are listed 'Best First'.
Re^2: Removal of duplicated element in array.
by choroba (Canon) on May 07, 2013 at 15:12 UTC
    Perl 5.8.0? What a pitty :-(
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Yeap! I know. When the OP kept complaining about virtually all the solution given and he/she said he/she is using v5.10.1.
      I thought if the solution am presenting works on a version as old as v5.8.0, then it should work on v5.10.1. That was why I mentioned that.

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (14)
As of 2015-07-31 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls