home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!umn.edu!news.d.umn.edu!ub.d.umn.edu!not-for-mail
- From: serickso@ub.d.umn.edu (Scott Erickson)
- Newsgroups: comp.lang.perl
- Subject: Removing duplicate array members. How?
- Date: 14 Dec 1992 14:40:39 -0600
- Organization: School of Conformist Thought
- Lines: 43
- Distribution: usa
- Message-ID: <1girg7INNh3b@ub.d.umn.edu>
- Reply-To: serickso@ub.d.umn.edu
- NNTP-Posting-Host: ub.d.umn.edu
-
- Hello:
-
- I am trying to remove duplicate members from an array. Is there any
- construct in Perl, such as maybe using grep, that will only give me an array
- with no duplicated members? An example:
-
- Contents of array @ARRAY: item1 item2 item2 item3
- Contents after removal: item1 item2 item3
-
- I have another array with members that are a subpart of the members of the
- first array. An example:
-
- Contents of array @ARRAY1: (part1 part2)1 (part1 part2)2
- Contents of array @ARRAY2: (part1)1 (part1)2
-
- I want to use the information of part2 of the items in the second array,
- but what I am doing later requires a loop and having duplicate members in the
- array is undesirable. The contents of the two arrays are acquired through
- different means. The contents of the one array arquired through the Unix
- command "finger" and the contents of the second command are acquired through
- either command line arguments or from standard input.
-
- I suppose I could use a loop and copy only single members to another array,
- but this is only useful if I have a small array.
-
- Also, I do not know the size of the array until during execution.
-
- In case you are wondering what this is for, I am writing a Perl script that
- when given a users login name will attempt to find out where they are and
- then display what room and/or what computer they are using. An example:
- %where serickso
- serickso: monh23913.d.umn.edu MonH239 Macintosh 13
-
- Most of our computers are ethernetted or connected to a Apple Localtalk
- network, thus in most cases I can determine exactly what computer they are
- at. This is useful if I want to find out where a friend of mine is. The
- only drawback is that I need to maintain a sitelist that maps a domain name
- to a room/computer.
-
- Your help will be appreciated.
-
- --
- serickso@ub.d.umn.edu Scott Erickson
-