Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!cunixf.cc.columbia.edu!cs.columbia.edu!dupuy From: dupuy@cs.columbia.edu (Alexander Dupuy) Newsgroups: comp.lang.perl Subject: Re: Help a perl apprentice Message-ID: Date: 29 Oct 90 03:57:26 GMT References: <18840001@hp-lsd.COS.HP.COM> <10080@jpl-devvax.JPL.NASA.GOV> Sender: news@cs.columbia.edu (The Daily News) Reply-To: dupuy@cs.columbia.edu Organization: Columbia University Computer Science Department Lines: 48 In-Reply-To: lwall@jpl-devvax.JPL.NASA.GOV's message of 23 Oct 90 18:13:32 GMT In article <10080@jpl-devvax.JPL.NASA.GOV> Larry Wall writes: | #!/usr/local/bin/perl | | open (BDF_PIPE, "bdf @ARGV |"); | | print <) { | ($fs, $kbytes, $used, $avail, $capacity, $dirname) = split; | next unless $kbytes > 0; | # next unless $fs; # uncomment to delete nfs filesystems | $line{$avail} = sprintf("%30.30s%10.1f%6s\n", | $dirname . '.' x 30, | $avail / 1000, $capacity); | } | | sub revnum { $b <=> $a; } | | foreach $key (sort revnum keys(%line)) { | print $line{$key}; | } | | print "\n"; | | We split just once per line, using a split that will leave $fs null on | the nfs lines. We find a single test that weeds out both the header | and the 1st of each pair of nfs lines. We make an associative array | keyed on the field we will sort on, formatting the output string | right then and there. Just hope that you never have two filesystems that are both 86% full, since you will only see the output for one of them. You have to be careful when manually optimizing a program that you don't change the semantics inadvertently... I would use the $dirname field as the key, and do an assoc array lookup in the revnum function, with the performance penalty, in order to know that I'm getting the right answer. @alex -- -- inet: dupuy@cs.columbia.edu uucp: ...!rutgers!cs.columbia.edu!dupuy