in reply to removing duplicated elements from array, with a difference

In one pass?? :^)

my %count; my @deduped = grep { $count{$_} == 1 } map { $count{$_} ++; $_ } @data +;

What's this about a "crooked mitre"? I'm good at woodwork!

Replies are listed 'Best First'.
Re: Re: removing duplicated elements from array, with a difference
by thelenm (Vicar) on Aug 28, 2002 at 18:37 UTC
    Well, that's still two passes, but it's one line, which gets a ++BrowserUk from me! :-)

    -- Mike

    --
    just,my${.02}

      Thanks for your help, but I've realised that I need to do the same problem except that the duplicate may be a particular pattern within an element. So therefore all those elements containing that pattern need to be removed. thanks again, paul

        This should do it if your pattern is can be reliably matched by a single regex

        my $pattern = qr/a regex that matches your pattern/; my @deduped = grep { !exists $count{$_} or $count{$_} == 1 } map { /$pattern/ and $count{$_} ++; $_ } @data;

        What's this about a "crooked mitre"? I'm good at woodwork!