Skip to content

Commit 44f2be4

Browse files
authored
primes: prompt for START and END in interactive mode
* Previously there was no way to specify the END value when starting primes with no arguments. * Previously there was no prompt given to indicate that the user needs to type a value for START * To me it makes more sense to show a prompt for both START and END * Clarify POD slightly
1 parent 6ef22ef commit 44f2be4

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

bin/primes

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,35 @@ my @primes = (2, 3, 5, 7, 11); # None have been tested
2323
my @next_primes = (); # Avoid redoing work
2424

2525

26-
my $VERSION = '1.002';
26+
my $VERSION = '1.003';
2727

2828
END {
2929
close STDOUT || die "$0: can't close stdout: $!\n";
3030
$? = 1 if $? == 255; # from die
3131
}
3232

33-
if (scalar(@ARGV) > 2) {
34-
require Pod::Usage;
35-
Pod::Usage::pod2usage({ -exitval => 1, -verbose => 0 });
33+
my ($start, $end);
34+
if (scalar(@ARGV) == 0) {
35+
print "Start [default 2]: ";
36+
chomp($start = <STDIN>);
37+
$start = 2 unless $start =~ m/\S/;
38+
print "End [default " . MAX . "]: ";
39+
chomp($end = <STDIN>);
40+
$end = MAX unless $end =~ m/\S/;
3641
}
37-
chomp(my $start = @ARGV ? $ARGV[0] : <STDIN>);
38-
my $end = defined $ARGV[1] ? $ARGV[1] : MAX;
42+
elsif (scalar(@ARGV) == 1) {
43+
$start = $ARGV[0];
44+
$end = MAX;
45+
}
46+
elsif (scalar(@ARGV) == 2) {
47+
$start = $ARGV[0];
48+
$end = $ARGV[1];
49+
}
50+
else {
51+
require Pod::Usage;
52+
Pod::Usage::pod2usage({ -exitval => 1, -verbose => 0 });
53+
}
54+
3955
for ($start, $end) {
4056
s/\A\s*\+?(\d{1,10})\Z/$1/ || die "$0: $_: illegal numeric format\n";
4157
$_ > MAX && die "$0: $_: Numerical result out of range\n";
@@ -125,10 +141,9 @@ I<stop>. The I<start> value must be at least 0 and not greater than
125141
stop. The I<stop> value must not be greater than 4294967295. The
126142
default value of I<stop> is 4294967295.
127143
128-
When the primes utility is invoked with no arguments, I<start> is read
129-
from standard input. I<stop> is taken to be 4294967295. The I<start>
130-
value may be preceded by a single C<+>. The I<start> value is
131-
terminated by a non-digit character (such as a newline).
144+
When the primes utility is invoked with no arguments, values are read
145+
from standard input. I<start> and I<stop> may be preceded by a single C<+>
146+
character.
132147
133148
=head1 BUGS
134149
@@ -147,4 +162,3 @@ This program is copyright (c) Jonathan Feinberg and Benjamin Tilly (1999).
147162
This program is free and open software. You may use, modify, distribute,
148163
and sell this program (and any modified variants) in any way you wish,
149164
provided you do not restrict others from doing the same.
150-

0 commit comments

Comments
 (0)