From owner-freebsd-questions@FreeBSD.ORG Fri Sep 14 08:35:19 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0F08616A417 for ; Fri, 14 Sep 2007 08:35:19 +0000 (UTC) (envelope-from jonathan+freebsd-questions@hst.org.za) Received: from hermes.hst.org.za (onix.hst.org.za [209.203.2.133]) by mx1.freebsd.org (Postfix) with ESMTP id 4928313C45E for ; Fri, 14 Sep 2007 08:35:17 +0000 (UTC) (envelope-from jonathan+freebsd-questions@hst.org.za) Received: from sysadmin.hst.org.za (sysadmin.int.dbn.hst.org.za [10.1.1.20]) (authenticated bits=0) by hermes.hst.org.za (8.13.8/8.13.8) with ESMTP id l8E8UkFF093921 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Fri, 14 Sep 2007 10:30:48 +0200 (SAST) (envelope-from jonathan+freebsd-questions@hst.org.za) From: Jonathan McKeown Organization: Health Systems Trust To: Steve Bertrand Date: Fri, 14 Sep 2007 10:37:52 +0200 User-Agent: KMail/1.7.2 References: <200709140930.21142.jonathan+freebsd-questions@hst.org.za> <46EA3B6C.7050200@ibctech.ca> In-Reply-To: <46EA3B6C.7050200@ibctech.ca> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200709141037.53071.jonathan+freebsd-questions@hst.org.za> X-Spam-Score: -4.241 () ALL_TRUSTED,AWL,BAYES_00 X-Scanned-By: MIMEDefang 2.61 on 209.203.2.133 Cc: Kurt Buff , freebsd-questions@freebsd.org Subject: Re: Scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Sep 2007 08:35:19 -0000 On Friday 14 September 2007 09:42, Steve Bertrand wrote: > >>> 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}; > 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 }; The problem with this is that it leaves you with one copy of each duplicated item: the requirement was to remove all copies of duplicated items and return only the non-repeated items. Jonathan