Skip to content

Commit dd06588

Browse files
authored
uniq: get_numeric_arg() versus empty string (#964)
* The uniq command expects a number argument to options -s and -f * Make $opt declaration clearer; it is not a parameter of get_numeric_arg() * Update validation to raise error for empty string (not a number) * Zero is allowed for -s and -f option arguments, so get_numeric_arg() allows it * Bump version
1 parent 3655a85 commit dd06588

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bin/uniq

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use strict;
1919
use constant EX_SUCCESS => 0;
2020
use constant EX_FAILURE => 1;
2121

22-
my $VERSION = '1.1';
22+
my $VERSION = '1.2';
2323

2424
END {
2525
close STDOUT || die "$0: can't close stdout: $!\n";
@@ -39,11 +39,12 @@ my ($optc, $optd, $optf, $opts, $optu);
3939

4040
sub get_numeric_arg {
4141
# $_ contains current arg
42-
my ($argname, $desc, $opt) = @_;
42+
my ($argname, $desc) = @_;
43+
my $opt;
4344
if (length) { $opt = $_ }
4445
elsif (@ARGV) { $opt = shift @ARGV }
4546
else {die "$0: option requires an argument -- $argname\n"}
46-
$opt =~ /\D/ && die "$0: invalid number of $desc: `$opt'\n";
47+
die "$0: invalid number of $desc: `$opt'\n" unless $opt =~ m/\A[0-9]+\Z/;
4748
$opt;
4849
}
4950

0 commit comments

Comments
 (0)