>>> I don't have the perl skills, though that would be ideal.

-- snip --

> Another approach in Perl would be:
> #!/usr/bin/perl
> my (%names, %dups);
> while (<>) {
>     my ($key) = split;
>     $dups{$key} = 1 if $names{$key};
>     $names{$key} = 1;
> }
> delete @names{keys %dups};
> #
> # keys %names is now an unordered list of only non-repeated elements
> # keys %dups is an unordered list of only repeated elements
> split splits on whitespace, returning a list of fields which can be assigned 
> to a list of variables. Here we only want to capture the first field: split 
> is more efficient for this than using a regex. The first occurrence of $key 
> is in parens because it's actually a list of one variable name.
> We build two hashes, one, %name, keyed by the original names (this is the 
> classic way to reduce duplicates to single occurrences, since the duplicated 
> keys overwrite the originals), and one, %dup, whose keys are names already 
> appearing in %names - the duplicated entries. Having done that we use a hash 
> slice to delete from %names all the keys of %dups, which leaves the keys of 
> %names holding all the entries which only appear once (and the keys of %dups 
> all the duplicated entries if that's useful).

I don't know if this is completely relevant, but it appears as though it
 may help.

Bob Showalter once advised me on the Perl Beginners list as such,
quoted, but snipped for clarity:

see "perldoc -q duplicate" If the array elements can
be compared with string semantics (as you are doing here), the following
will work:

   my @array = do { my %seen; grep !$seen{$_}++, @clean };

freebsd-questions@freebsd.org mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to