home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7461 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.4 KB  |  38 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!europa.asd.contel.com!emory!sol.ctr.columbia.edu!eff!ckd
  3. From: ckd@eff.org (Christopher Davis)
  4. Subject: Re: using grep to extracting matching elements from an array
  5. In-Reply-To: kron@ueshiba.Corp.Sun.COM's message of 15 Dec 1992 23:28:24 GMT
  6. Message-ID: <CKD.92Dec16135228@loiosh.eff.org>
  7. Sender: usenet@eff.org (NNTP News Poster)
  8. Nntp-Posting-Host: loiosh.eff.org
  9. Organization: Electronic Frontier Foundation Tech Central
  10. References: <lisqgoINN14k@jethro.Corp.Sun.COM>
  11. Date: Wed, 16 Dec 1992 18:52:30 GMT
  12. Lines: 24
  13.  
  14. KK> == Kenneth Kron <kron@ueshiba.Corp.Sun.COM>
  15.  
  16.  KK> I'd like to count the number of elements in an associative array whose
  17.  KK> keys match an re.
  18.  
  19.  KK> @Group = grep("home", keys %LocalDisks) ;
  20.  KK> print join(" ", @Group) ;
  21.  
  22.  KK> But group is always ALL the keys.
  23.  
  24. "home" is a true value.
  25.  
  26. /home/ is a regexp match for "home" on $_.
  27.  
  28.  KK> I know there are other ways to do this but what I want to know is what
  29.  KK> don`t I understand about the GREP FUNCTION???
  30.  
  31. It evaluates the first item in the list as an expression, and if it gets a
  32. true value, puts the current element into its return list.
  33. --
  34. Christopher K. Davis      | ``Usenet seems to run much like the Kif (or,
  35. <ckd@eff.org>   EFF #14   |   for the TV generation, Klingon) high command.
  36. System Administrator, EFF |   Whoever takes action and can be heard wins.''
  37. +1 617 864 0665  [CKD1]   |   --Peter da Silva <peter@ferranti.com>
  38.