1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- use strict;
- my $filename = $ARGV[0];
- if (!$filename) {
- print "Usage: longlines.pl <filename> [length]\n";
- exit(1);
- }
- my $max_length = $ARGV[1] || 80;
- my @lines = ();
- my $line_num = 0;
- open(HANDLE, "<", $filename) or die "Cannot open $filename\n";
- while (<HANDLE>) {
- $line_num++;
-
-
- if (length($_) - 1 > $max_length) {
- push @lines, $line_num;
- }
- }
- if (@lines > 5) {
- @lines = @lines[0..4];
- push @lines, "and others";
- }
- if (@lines) {
- print $filename." (line".((@lines > 1) ? "s" : "")." ".
- join(", ", @lines)." exceed".((@lines == 1) ? "s" : "").
- " length $max_length)\n";
- exit(1);
- } else {
- exit(0);
- }
|