#!/usr/bin/perl
#   FileSizes [dir]...
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# This program runs thru the directories  and  collects  statistics  on  file #
# sizes. The output will have a line per filename found, showing the sizes in #
# the directories.  At the left will be the ratio  between  the  largest  and #
# smallest,  and  at  the  right  will be the file name.  Note that files are #
# omitted if all the sizes are the same.                                      #
#                                                                             #
# If "-" is used as a command-line arg, it means to read stdin, which  should #
# be  output  from  "ls -l" ("ls -lg" if Sys/V ;-).  The file names and sizes #
# will be extraced from the input and added to the $min{} and $max{} arrays.  #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

for $d (@ARGV) {
	if ($d eq '-') {
		for (<>) {
			chop;
#			print "Line: \"$_\"\n";
			if (/^[-drwxsSt]+\s+[0-9]+\s+.+\s+([0-9]+)\s+\w\w\w\s+[0-9]+\s+[0-9:]+\s+(.+)$/) {
				$s = $1;
				$f = $2;
				if (!defined $min{$f} || $s < $min{$f}) { $min{$f} = $s; }
				if (!defined $max{$f} || $s > $max{$f}) { $max{$f} = $s; }
			}
		}
	} elsif (opendir(D,$d)) {
		for $f (readdir(D)) {
			$p = "$d/$f";
			next if ($f =~ /^\./);
			$s = -s $p;
			if (!defined $min{$f} || $s < $min{$f}) { $min{$f} = $s; }
			if (!defined $max{$f} || $s > $max{$f}) { $max{$f} = $s; }
		}
		closedir(D);
	}
}
for $f (sort keys %min) {
	if ($min{$f} != $max{$f}) {
		$ratio = $max{$f} / ($min{$f} || 1);
		write;
	}
}
format STDOUT =
@####.### @######## @######## @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$ratio,  $min{$f} , $max{$f}, $f
.
