home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4854 < prev    next >
Encoding:
Text File  |  1992-07-21  |  3.2 KB  |  87 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!centerline!noc.near.net!news.cs.brandeis.edu!chaos.cs.brandeis.edu!cos
  3. From: cos@chaos.cs.brandeis.edu (Ofer Inbar)
  4. Subject: Re: easier way to determine set membership?
  5. Message-ID: <cos.711749926@chaos.cs.brandeis.edu>
  6. Sender: news@news.cs.brandeis.edu (USENET News System)
  7. Organization: Brandeis University
  8. References: <1992Jul16.114212.25934@hemlock.cray.com> <1992Jul16.180214.17784@news.eng.convex.com> <1992Jul17.181921.27622@spillman.uucp> <1992Jul17.191949.2306@news.eng.convex.com> <1992Jul21.020640.33936@spillman.uucp>
  9. Date: Tue, 21 Jul 1992 20:18:46 GMT
  10. Lines: 75
  11.  
  12. tye@spillman.uucp (E. Tye McQueen) writes:
  13. >Tom Christiansen <tchrist@convex.COM> writes:
  14. >)From the keyboard of tye@spillman.uucp (E. Tye McQueen):
  15. >):    @list =   ('bob', 'fred', 'joe', 'george');
  16. >):    @group{@list} = (1) x @list;
  17. >)
  18. >)Um, yes, that's an exact quote from the posting of mine that
  19. >)you quoted.  What's the difference?
  20. >
  21. >From memory your posting had the last line of:
  22. >
  23. >    @group{@list} = ();
  24. >
  25. >and a note about how this is a bit of a pain because you can't just
  26. >check for "true".  My, admitedly slight, modification allows you
  27. >to simply use $group{$element} as a boolean.
  28.  
  29. From TomC's original posting:
  30. >Using as associative array is the right way to go for sets.
  31. >A grep can pretty much always replace a for loop (except
  32. >that you can't last out of it.)
  33. >
  34. >    grep ($group{$_}++,  'bob', 'fred', 'joe', 'george');
  35. >    print "$x is ", ($group{$x} ? "" : "not "),  "a member\n";
  36. >
  37. >or
  38. >
  39. >    @list =   ('bob', 'fred', 'joe', 'george');
  40. >    grep ($group{$_}++,  @list);
  41. >    print "$x is ", ($group{$x} ? "" : "not "),  "a member\n";
  42. >
  43. >or
  44. >    @list =   ('bob', 'fred', 'joe', 'george');
  45. >    @group{@list} = (1) x @list;
  46.  
  47. Look at the last two lines above.  This is what Tom was referring to
  48. when he said you made an exact quote from his posting.  You did :-)
  49.  
  50. And later on, from TomC's original posting:
  51. >BTW, if you just want to make keys, you could do this:
  52. >
  53. >    @list =   ('bob', 'fred', 'joe', 'george');
  54. >    @group{@list} = ();
  55. >
  56. >But then you can't really check $group{$member}, since its value will be
  57. >undef.  But you can check it using keys() if you want.
  58.  
  59. Note the "if you just want to make keys."  Your correction to the
  60. above section was actually a bug :-) since it took code meant to "just
  61. make keys" and made it make keys *and* values instead.
  62.  
  63. Larry Wall then wrote:
  64. >In article <1992Jul16.180214.17784@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
  65. >: BTW, if you just want to make keys, you could do this:
  66. >: 
  67. >:     @list =   ('bob', 'fred', 'joe', 'george');
  68. >:     @group{@list} = ();
  69. >: 
  70. >: But then you can't really check $group{$member}, since its value will be
  71. >: undef.  But you can check it using keys() if you want.
  72. >
  73. >Or say
  74. >
  75. >    @group{@list} = (1) x @list;
  76. >
  77. >Larry
  78.  
  79.   Well, I guess if Larry can make the same mistake, that gives it a
  80. measure of respectability, eh?  Guess you don't have to feel too bad
  81. about it :-).  Aren't these misunderstandings fun!
  82.  
  83.   --  Cos (Ofer Inbar)  --  cos@chaos.cs.brandeis.edu
  84.   --  WBRS (BRiS)  --  WBRS@binah.cc.brandeis.edu  WBRS@brandeis.bitnet
  85.   "Good literature is about Love and War."
  86.   "Junk fiction is about Sex and Violence."
  87.