On Tue, 15 Sep 1998 12:51:04 James wrote:
> thought this might help someone, wrote it whilst trying to work out
> where all my harddrive space had gone...
>
> $ du -bax | sort -rn +0 | less
>
> it'll display all your files and directories, sorted with the biggest
> first (which'll always be . so ignore the top line). It only searches the
> current drive (otherwise it'd go off down all your NFS links and dos mounted
> partitions ( = slow)) just remove the x from du if you want it to do that.
>
> it's probably really inefficiant and will probably give you a load average
> of 2, but never mind :)
>
> go on... show me a perl program that does the same, and only shows the
> bigges and smallest FILE :)
You are comparing apples and perls. Perl is designed to coexist with virtually
everything (if you include extentions). Of the many Perlism that could apply
here it has been described as the "swiss army knife of scripting languages" and
"there always more than one way to do things in perl". The following is offered
as an illustration.
time du -ba /home/davidr | perl -e 'print(sort {($a<=>$b)*-1;} (<>));' | wc -l
4609
real 0m12.54s
user 0m3.70s
sys 0m8.01s
time du -ba /home/davidr | sort -rn | wc -l
4609
real 0m10.78s
user 0m1.64s
sys 0m8.35s
The entire pipe could be witten in perl. The real question is why bother.
In some ways perl is unique amoung computer languages. I recall reading a
statement by Larry Wall that perl was not designed (before version 5.0), but was
assembled as a collection of idiums. A lot was copied directly from unix in
general and shell script languages in particular and C. Perl roots are spread so
far and wide that it has been critised for inconsistent and at times cryptic
syntax.
I understand his intent to be to provide a natural way to express useful
solutions to problems. What is natural is determined in the eye of the creator.
What is useful is decided of those affected by the problem. This approach and
perl's internals reflect his training as a linguist.
IMHO 20% overhead is a very price to pay for the use of interpretive language
that is capable of supporting elegant implementations of the largest and most
complex systems. Mileage will vary widely, but if its too slow there is usually
a way to make it run fast enough.
If you are interested in speed for sorting a good of mainframesk sorting utility
like OTSORT (commercial) is an order of magnitude faster than the unix sort for
significant volumes. If your professional perspective is limited to a series of
immediate small problems then commands and pipes are all that you need. If you
subscript to the notion that history repeats itself, but you have to keep the
alligators at bay while working toward draining the swamp then you have to work
at making all tools and resources your ally.
David Ross
[EMAIL PROTECTED]
Toad Technologies
"I'll be good! I will, I will !"