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

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!exodus.Eng.Sun.COM!jethro.Corp.Sun.COM!ueshiba!kron
  2. From: kron@ueshiba.Corp.Sun.COM (Kenneth Kron)
  3. Newsgroups: comp.lang.perl
  4. Subject: using grep to extracting matching elements from an array
  5. Date: 15 Dec 1992 23:28:24 GMT
  6. Organization: Sun Microsystems, Inc.
  7. Lines: 30
  8. Distribution: world
  9. Message-ID: <lisqgoINN14k@jethro.Corp.Sun.COM>
  10. Reply-To: kron@ueshiba.Corp.Sun.COM
  11. NNTP-Posting-Host: ueshiba.corp.sun.com
  12.  
  13. I'd like to count the number of elements in an associative array whose keys match an re.
  14.  
  15. For example I'd like to know how many of the mounted file systems start with "home".
  16.     Note this is a simple example,  I really need to
  17.         "count the number of keys in an associative array that match an re"
  18.  
  19. open(LocalDisk, "df -t 4.2|") ;
  20. <LocalDisk> ;    # throw away first line
  21. while(<LocalDisk>) {
  22.     chop ;
  23.     ($junk, $junk, $used, $junk, $junk, $Dir )= split ;
  24.     $LocalDisks{$Dir} = "$used" ;
  25. }
  26. @Group = grep("home", keys %LocalDisks) ;
  27. print join(" ", @Group) ;
  28.  
  29.  
  30. But group is always ALL the keys.
  31.  
  32. I know there are other ways to do this but what I want to know is what
  33. don`t I understand about the GREP FUNCTION???
  34.  
  35.  
  36. tnx
  37.  
  38. ---
  39. kron@ueshiba.sun.com
  40. 'Whatever you can do, or dream you can, begin it.  Boldness
  41. has genius, power and magic in it.'  -  Goethe
  42.  
  43.