home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!roehrich
- From: roehrich@cray.com (Dean Roehrich)
- Subject: Re: # of files in directory
- Message-ID: <1992Jul23.175029.27400@hemlock.cray.com>
- Keywords: Files, Perl, Directory, ls
- Lines: 28
- Organization: Cray Research, Inc.
- References: <1992Jul23.195931.20791@magnus.acs.ohio-state.edu> <1992Jul23.201539.4416@news.eng.convex.com> <1992Jul23.211249.21744@magnus.acs.ohio-state.edu>
- Date: 23 Jul 92 17:50:29 CDT
-
- In article <1992Jul23.211249.21744@magnus.acs.ohio-state.edu> bobd@magnus.acs.ohio-state.edu (Bob DeBula) writes:
- >In article <1992Jul23.201539.4416@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
- >>From the keyboard of bobd@magnus.acs.ohio-state.edu (Bob DeBula):
- >>:To reduce it still further (this *is* PERL after all):
- >>:
- >>:opendir (FILE, "/usr/bin");
- >>:print "There are ", scalar(grep (!/^\./, readdir (FILE))), " files!\n";
- >>:
- >>:Now if I could just figure out how to embed the open in the print
- >>:statement.....
- >>
- >>print "There are ", scalar grep(1,`ls /usr/bin/`), " files in /usr/bin.\n";
-
-
- A one-liner? You people forgot to close FILE :)
- Here you go:
-
-
- print( "There are ", scalar( opendir( FILE, "/usr/bin/" ),
- @files = grep (!/^\./, readdir (FILE))), " files!\n") && close FILE;
-
-
-
- Dean Roehrich
- roehrich@cray.com
-
-
- p.s. Didn't the original poster want to keep the file names?
-