home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!centerline!noc.near.net!news.cs.brandeis.edu!chaos.cs.brandeis.edu!cos
- From: cos@chaos.cs.brandeis.edu (Ofer Inbar)
- Subject: Re: easier way to determine set membership?
- Message-ID: <cos.711749926@chaos.cs.brandeis.edu>
- Sender: news@news.cs.brandeis.edu (USENET News System)
- Organization: Brandeis University
- 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>
- Date: Tue, 21 Jul 1992 20:18:46 GMT
- Lines: 75
-
- tye@spillman.uucp (E. Tye McQueen) writes:
- >Tom Christiansen <tchrist@convex.COM> writes:
- >)From the keyboard of tye@spillman.uucp (E. Tye McQueen):
- >): @list = ('bob', 'fred', 'joe', 'george');
- >): @group{@list} = (1) x @list;
- >)
- >)Um, yes, that's an exact quote from the posting of mine that
- >)you quoted. What's the difference?
- >
- >From memory your posting had the last line of:
- >
- > @group{@list} = ();
- >
- >and a note about how this is a bit of a pain because you can't just
- >check for "true". My, admitedly slight, modification allows you
- >to simply use $group{$element} as a boolean.
-
- From TomC's original posting:
- >Using as associative array is the right way to go for sets.
- >A grep can pretty much always replace a for loop (except
- >that you can't last out of it.)
- >
- > grep ($group{$_}++, 'bob', 'fred', 'joe', 'george');
- > print "$x is ", ($group{$x} ? "" : "not "), "a member\n";
- >
- >or
- >
- > @list = ('bob', 'fred', 'joe', 'george');
- > grep ($group{$_}++, @list);
- > print "$x is ", ($group{$x} ? "" : "not "), "a member\n";
- >
- >or
- > @list = ('bob', 'fred', 'joe', 'george');
- > @group{@list} = (1) x @list;
-
- Look at the last two lines above. This is what Tom was referring to
- when he said you made an exact quote from his posting. You did :-)
-
- And later on, from TomC's original posting:
- >BTW, if you just want to make keys, you could do this:
- >
- > @list = ('bob', 'fred', 'joe', 'george');
- > @group{@list} = ();
- >
- >But then you can't really check $group{$member}, since its value will be
- >undef. But you can check it using keys() if you want.
-
- Note the "if you just want to make keys." Your correction to the
- above section was actually a bug :-) since it took code meant to "just
- make keys" and made it make keys *and* values instead.
-
- Larry Wall then wrote:
- >In article <1992Jul16.180214.17784@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
- >: BTW, if you just want to make keys, you could do this:
- >:
- >: @list = ('bob', 'fred', 'joe', 'george');
- >: @group{@list} = ();
- >:
- >: But then you can't really check $group{$member}, since its value will be
- >: undef. But you can check it using keys() if you want.
- >
- >Or say
- >
- > @group{@list} = (1) x @list;
- >
- >Larry
-
- Well, I guess if Larry can make the same mistake, that gives it a
- measure of respectability, eh? Guess you don't have to feel too bad
- about it :-). Aren't these misunderstandings fun!
-
- -- Cos (Ofer Inbar) -- cos@chaos.cs.brandeis.edu
- -- WBRS (BRiS) -- WBRS@binah.cc.brandeis.edu WBRS@brandeis.bitnet
- "Good literature is about Love and War."
- "Junk fiction is about Sex and Violence."
-