Path: utzoo!attcan!uunet!cs.utexas.edu!usc!ucsd!rutgers!orstcs!sapphire!pvo From: pvo@sapphire.OCE.ORST.EDU (Paul O'Neill) Newsgroups: comp.lang.perl Subject: Cute hack around tiny bug (Re: Help a perl apprentice) Message-ID: <21380@orstcs.CS.ORST.EDU> Date: 28 Oct 90 04:36:52 GMT References: <18840001@hp-lsd.COS.HP.COM> Sender: usenet@orstcs.CS.ORST.EDU Reply-To: pvo@sapphire.OCE.ORST.EDU (Paul O'Neill) Organization: Coastal Imaging Lab, Oregon State University, Corvallis, OR Lines: 57 I really like Tim Chambers' df massager and Larry's rewrite of it. ------------- #!/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"; ---------------------- There's a tiny bug in there, though. What if 2 file systems have the same available space? (ie. zero :-) The old $line{$avail} gets wiped by the new $line{$avail} and is not reported. It occured to me that a good way to handle this was to add a small number, say 0.1, to $avail if $line{$avail} aready existed. But what if there were *three* (or more) file systems with the exact same available space? Hmm... What's a neat way of adding 0.1 to $avail recursively??? Bingo!! Don't bother. Just add rand() to $avail! # next unless $fs; # uncomment to delete nfs filesystems + $line{$avail} && $avail += rand; $line{$avail} = sprintf("%30.30s%10.1f%6s\n", Hope you can use this some day .... ps--the commented nfs remover just removes nfs mounts with long path's. Paul O'Neill pvo@oce.orst.edu DoD 000006 Coastal Imaging Lab OSU--Oceanography Corvallis, OR 97331 503-737-3251