in reply to Removing duplicates from list

That's what hashes are good at. Since keys have to be unique, just plop your parsed version of $mer into a hash as the hash's key. Value is unimportant, though you could use it as a counter.

Example just teaking your code slightly:

use strict; use warnings; open (MER, "Extracted.c") or die "Can't open input file. $!\n"; my %cases; for my $mer(<Mer>){ my $control; while ($control!=15){ $mer =~ s/ //; $control++; } $cases{$mer}++; } foreach $key ( keys %cases ) { print $key, "\n"; }

I'm not really clear on that the inner loop is for. You only want to remove the first fifteen spaces from $mer? ...ok. I guess that's working out ok. You could alternatively use something like:

substr($mer,0,15) =~ s/ //g;

That would eliminate the while loop and $control counter.


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: Re: Removing duplicates from list
by Levan (Novice) on Oct 14, 2003 at 07:20 UTC
    hi,
    thanks for your advice, i have got it to work. by the way, the while loop is to help me align the list to the left as there are some spaces in front. your code really helps!!!
    a thousand thanks!!!
    Levan