Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Removal of duplicated element in array.

by Laurent_R (Prior)
on May 07, 2013 at 09:28 UTC ( #1032455=note: print w/ replies, xml ) Need Help??


in reply to Removal of duplicated element in array.

Hi,

I do not know what you changed, but taking your original program, changing the split pattern to /\n/ (and adding a few prints just to show the content of the various variables) show that this works perfectly.

my $match = "foo1\nfoo2\nfoo3\nfoo4\nfoo5\nfoo3\nfoo2"; print '$match = ', "\n", $match, "\n\n"; my @match_to_array = split /\n/, $match; print '@match_to_array = ', "@match_to_array \n\n"; my %seen = (); my @r = (); foreach my $a (@match_to_array) { unless ($seen{$a}) { push @r, $a; $seen{$a}++; } } print '@r = ', "@r";

This is now the output:

$ perl remove_duplicates.pl $match = foo1 foo2 foo3 foo4 foo5 foo3 foo2 @match_to_array = foo1 foo2 foo3 foo4 foo5 foo3 foo2 @r = foo1 foo2 foo3 foo4 foo5

The duplicate values (foo3 and foo2) have been duly removed.


Comment on Re: Removal of duplicated element in array.
Select or Download Code
Re^2: Removal of duplicated element in array.
by Laurent_R (Prior) on May 07, 2013 at 17:52 UTC

    The problem is simply that the OP is making the suggested corrections on a piece of code that is different from what he has presented (as he has admitted in his cross-post on a different forum).

    @ tty1x: we cannot guess what other bugs you have in your code if you don't tell us what this code is.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-07-03 22:02 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 (56 votes), past polls