home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4928 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.4 KB  |  40 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!roehrich
  3. From: roehrich@cray.com (Dean Roehrich)
  4. Subject: Re: # of files in directory
  5. Message-ID: <1992Jul23.175029.27400@hemlock.cray.com>
  6. Keywords: Files, Perl, Directory, ls
  7. Lines: 28
  8. Organization: Cray Research, Inc.
  9. References: <1992Jul23.195931.20791@magnus.acs.ohio-state.edu> <1992Jul23.201539.4416@news.eng.convex.com> <1992Jul23.211249.21744@magnus.acs.ohio-state.edu>
  10. Date: 23 Jul 92 17:50:29 CDT
  11.  
  12. In article <1992Jul23.211249.21744@magnus.acs.ohio-state.edu> bobd@magnus.acs.ohio-state.edu (Bob DeBula) writes:
  13. >In article <1992Jul23.201539.4416@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
  14. >>From the keyboard of bobd@magnus.acs.ohio-state.edu (Bob DeBula):
  15. >>:To reduce it still further (this *is* PERL after all):
  16. >>:
  17. >>:opendir (FILE, "/usr/bin");
  18. >>:print "There are ", scalar(grep (!/^\./, readdir (FILE))), " files!\n";
  19. >>:
  20. >>:Now if I could just figure out how to embed the open in the print
  21. >>:statement.....
  22. >>
  23. >>print "There are ", scalar grep(1,`ls /usr/bin/`), " files in /usr/bin.\n";
  24.  
  25.  
  26. A one-liner?  You people forgot to close FILE :)
  27. Here you go:
  28.  
  29.  
  30. print( "There are ", scalar( opendir( FILE, "/usr/bin/" ),
  31.      @files = grep (!/^\./, readdir (FILE))), " files!\n") && close FILE;
  32.  
  33.  
  34.  
  35. Dean Roehrich
  36. roehrich@cray.com
  37.  
  38.  
  39. p.s. Didn't the original poster want to keep the file names?
  40.