Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nferraz committed Sep 9, 2013
1 parent 550f0aa commit 29e6f5f
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions bin/st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ GetOptions(
'format|fmt|f=s',
'no-header|nh',
'transverse-output|to',

# error handling
'quiet|q',
'strict',

'help|h',
) or pod2usage(1);
Expand Down Expand Up @@ -81,7 +84,12 @@ while (my $num = <>) {
| [0-9]* \. [0-9]+ E [+-]? [0-9]+
)
$}x) {
warn "Invalid number '$num'\n" unless $opt{quiet};
my $err = "Invalid value '$num' on input line $.\n";
if ($opt{strict}) {
die $err;
} elsif (!$opt{quiet}) {
warn $err;
}
next;
}

Expand Down Expand Up @@ -268,7 +276,16 @@ The following options are available:
--no-header|nh # don't display header
--transverse-output|to # output in multiple lines
--quiet|q # silently skip invalid input
=head2 ERROR HANDLING
What happens if "st" finds non-numeric data? By default it will
emit a warning, skip the current line and continue.
You can change this behavior with the following options:
--quiet|q # silently skip invalid input (no warning)
--strict # interrupt process
=head2 EXAMPLES
Expand All @@ -286,14 +303,7 @@ The following options are available:
Nelson Ferraz L<<[email protected]>>
=head1 CONTRIBUTORS
imurray, who suggested a different algorithm for calculating variance.
asgeirn, who suggested a input filter and helped to remove some
warnings.
gabeguz, who modified the script to make it more portable.
=head1 CONTRIBUTING
Send comments, suggestions and bug reports to:
Expand All @@ -303,6 +313,15 @@ Or fork the code on github:
https://github.com/nferraz/st
=head2 THANKS
imurray, who suggested a different algorithm for calculating variance.
asgeirn, who suggested a input filter and helped to remove some
warnings.
gabeguz, who modified the script to make it more portable.
=head1 COPYRIGHT
Copyright (c) 2013 Nelson Ferraz.
Expand Down

0 comments on commit 29e6f5f

Please sign in to comment.