in reply to removing duplicates entries from an array

What's with all the options on that regexp? igcgxm?? And assuming $serviceName and $dll are strings, not regexp, you don't even quote your variables?

Your sorting before removing the duplicates, when it would be cheaper to sort after they have been removed (since you algorithm don't take into account the fact that the array is sorted).

join(" ", split " ", $elem) is very weird too.

When you want unique, use a hash!

sub RDup { my %unique; $unique{lc($_)} = $_ foreach @_; return sort values %unique; } my @unique; foreach $d (@dllExeLines) { if ($d =~ /\Q$serviceName/) { foreach $f (split(/,/, $d)) { if ($f =~ /\Q$dll/i) { push @unique, $dll; } } } } @unique = RDup(@unique);

Replies are listed 'Best First'.
Re^2: removing duplicates entries from an array
by kulls (Hermit) on Jan 06, 2006 at 17:18 UTC
    We can directly replace   push @unique, $dll; with  $unique{$dll}=1 .
    why not ?
    - kulls
      Yes, RDup could be eliminated. I didn't remove it for the sake of reusability.
      my %unique; foreach $d (@dllExeLines) { if ($d =~ /\Q$serviceName/) { foreach $f (split(/,/, $d)) { if ($f =~ /\Q$dll/i) { $unique{lc($dll)} = $dll; } } } } my @unique = sort values %unique;