From cc16a0d7c358141e0ceb2fef7d7c5572bcc6d385 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 1 Feb 2014 19:32:26 +0100 Subject: long-lines.pl: Error handling Signed-off-by: Florian Pritz --- long-lines.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'long-lines.pl') diff --git a/long-lines.pl b/long-lines.pl index c0e1da0..f0a117f 100755 --- a/long-lines.pl +++ b/long-lines.pl @@ -4,6 +4,7 @@ use strict; use File::Basename; use Getopt::Std; use Text::Tabs; +use Carp; my %opt; getopts("hm:t:", \%opt); @@ -25,13 +26,15 @@ $max = $opt{m} if ($opt{m}); $Text::Tabs::tabstop = $opt{t} if ($opt{t}); for my $file (@ARGV) { - open FILE,"<", $file; + open my $fh,"<", $file or do {carp "Failed to open $file: $!"; next;}; + $line = 0; - while () { + while (<$fh>) { $line++; $_ = expand $_; if (length > $max) { print "\"$file\" - line $line: ", length, " chars\n"; } } + close $fh; } -- cgit v1.2.3-24-g4f1b