home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7418 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  2.2 KB

  1. Path: sparky!uunet!spool.mu.edu!umn.edu!news.d.umn.edu!ub.d.umn.edu!not-for-mail
  2. From: serickso@ub.d.umn.edu (Scott Erickson)
  3. Newsgroups: comp.lang.perl
  4. Subject: Removing duplicate array members. How?
  5. Date: 14 Dec 1992 14:40:39 -0600
  6. Organization: School of Conformist Thought
  7. Lines: 43
  8. Distribution: usa
  9. Message-ID: <1girg7INNh3b@ub.d.umn.edu>
  10. Reply-To: serickso@ub.d.umn.edu
  11. NNTP-Posting-Host: ub.d.umn.edu
  12.  
  13. Hello:
  14.  
  15.   I am trying to remove duplicate members from an array.  Is there any
  16. construct in Perl, such as maybe using grep, that will only give me an array
  17. with no duplicated members? An example:
  18.  
  19. Contents of array @ARRAY:  item1 item2 item2 item3
  20. Contents after removal:    item1 item2 item3
  21.  
  22.   I have another array with members that are a subpart of the members of the
  23. first array.  An example:
  24.  
  25. Contents of array @ARRAY1: (part1 part2)1 (part1 part2)2
  26. Contents of array @ARRAY2: (part1)1 (part1)2
  27.  
  28.   I want to use the information of part2 of the items in the second array,
  29. but what I am doing later requires a loop and having duplicate members in the
  30. array is undesirable.  The contents of the two arrays are acquired through
  31. different means.  The contents of the one array arquired through the Unix
  32. command "finger" and the contents of the second command are acquired through
  33. either command line arguments or from standard input.
  34.  
  35.   I suppose I could use a loop and copy only single members to another array,
  36. but this is only useful if I have a small array.
  37.  
  38.   Also, I do not know the size of the array until during execution.
  39.  
  40.   In case you are wondering what this is for, I am writing a Perl script that
  41. when given a users login name will attempt to find out where they are and
  42. then display what room and/or what computer they are using.  An example:
  43. %where serickso
  44. serickso: monh23913.d.umn.edu MonH239 Macintosh 13
  45.  
  46.   Most of our computers are ethernetted or connected to a Apple Localtalk
  47. network, thus in most cases I can determine exactly what computer they are
  48. at.  This is useful if I want to find out where a friend of mine is.  The
  49. only drawback is that I need to maintain a sitelist that maps a domain name
  50. to a room/computer.
  51.  
  52.   Your help will be appreciated.
  53.  
  54. -- 
  55. serickso@ub.d.umn.edu                                         Scott Erickson
  56.