#!/usr/bin/perl
#
# Find the length of the longest line in the input, which may be files
# named on the command line, or stdin.

$exitstat = 0;	# Count of failures.

for $file (@ARGV) {
	++$files;
	if (open(STDIN,$file)) {
		&onefile();
	} else {
		print STDERR "$0: Can't read \"$file\" ($!)\n";
		++$exitstat;
	}
}
&onefile() unless $files > 0;

exit $exitstat;

sub onefile {
	$len = 0;
	for $line (<STDIN>) {
		$line =~ s/[\r\n]+$//;
		$len = length($line) if (length($line) > $len);
	}
	printf "%5d %s\n", $len, $file;
}
