home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!cs.utexas.edu!convex!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: # of files in directory
- Message-ID: <1992Jul23.225715.21531@news.eng.convex.com>
- Originator: tchrist@pixel.convex.com
- Keywords: Files, Perl, Directory, ls
- Sender: usenet@news.eng.convex.com (news access account)
- Nntp-Posting-Host: pixel.convex.com
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- Organization: CONVEX Realtime Development, Colorado Springs, CO
- 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: Thu, 23 Jul 1992 22:57:15 GMT
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 65
-
- From the keyboard of bobd@magnus.acs.ohio-state.edu (Bob DeBula):
- :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";
- : ^^^^^^^^^^^^^^
- : But, that would
- : be *cheating* :-)
- :
- :
- :Actually, how does this compare in efficiency to the "opendir"
- :method? (My timings would seem to indicate that the "opendir" form
- :is slightly (almost infintesimally) faster on my Sun 3/80).
-
- Right -- depends on your system and the phase of the moon.
-
- On mine, opendir() is method 1, `ls` is method 2, and I ran 100
- iterations:
-
- method 1: 1.1500u 0.2333s
- method 2: 1.0667u 0.6833s
-
- :While the goal is to get it down to one line, you must color
- :in the lines (stay within PERL that is :-). So, can you do it
- :in one line *without* using any semi-colons or backquoting
- :to use external utilities?
-
- Surely.
-
- print "There are ",
- scalar(opendir(F,"/usr/bin"),scalar(grep(!/^\./,readdir(F)))),
- " files!\n"
-
- You can join these into one line if you'd like.
-
- :Think of it as one of those penultimately
- :pointless PERL challenges which crop up from time to time :-)
-
- Sigh, pretty as it sounds, I lament to inform you that penultimate doesn't
- mean more than ultimate. Ultimate often means last in modern dialects of
- Latin. Penultimate means second to the last, and antepenultimate means
- third to the last.
-
- :Hmmm, "Penultimately Pointless PERL Programming Problem" sounds
- :like some sort of invitational named by Robin Leach, doesn't it?
- :What would we give for a prize to the winner of the 1st PPPPP
- :Invitational? Maybe we could get Larry to donate some "suitable
- :for framing" original napkins with PERL patches scribbled on them
- :(complete with obligatory coffee stains)?
-
- But I do like the idea.
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
- Besides, including <std_ice_cubes.h> is a fatal error on machines that
- don't have it yet. Bad language design, there... :-)
- --Larry Wall in <1991Aug22.220929.6857@netlabs.com>
-