home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!exodus.Eng.Sun.COM!jethro.Corp.Sun.COM!ueshiba!kron
- From: kron@ueshiba.Corp.Sun.COM (Kenneth Kron)
- Newsgroups: comp.lang.perl
- Subject: using grep to extracting matching elements from an array
- Date: 15 Dec 1992 23:28:24 GMT
- Organization: Sun Microsystems, Inc.
- Lines: 30
- Distribution: world
- Message-ID: <lisqgoINN14k@jethro.Corp.Sun.COM>
- Reply-To: kron@ueshiba.Corp.Sun.COM
- NNTP-Posting-Host: ueshiba.corp.sun.com
-
- I'd like to count the number of elements in an associative array whose keys match an re.
-
- For example I'd like to know how many of the mounted file systems start with "home".
- Note this is a simple example, I really need to
- "count the number of keys in an associative array that match an re"
-
- open(LocalDisk, "df -t 4.2|") ;
- <LocalDisk> ; # throw away first line
- while(<LocalDisk>) {
- chop ;
- ($junk, $junk, $used, $junk, $junk, $Dir )= split ;
- $LocalDisks{$Dir} = "$used" ;
- }
- @Group = grep("home", keys %LocalDisks) ;
- print join(" ", @Group) ;
-
-
- But group is always ALL the keys.
-
- I know there are other ways to do this but what I want to know is what
- don`t I understand about the GREP FUNCTION???
-
-
- tnx
-
- ---
- kron@ueshiba.sun.com
- 'Whatever you can do, or dream you can, begin it. Boldness
- has genius, power and magic in it.' - Goethe
-
-