From 44f2be4c9fa486943aedb4f47c8c8d9bbe1df78d Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Tue, 4 Nov 2025 18:18:15 +0800 Subject: [PATCH] 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 --- bin/primes | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/bin/primes b/bin/primes index 0eb32ed5..66e14e21 100755 --- a/bin/primes +++ b/bin/primes @@ -23,19 +23,35 @@ my @primes = (2, 3, 5, 7, 11); # None have been tested my @next_primes = (); # Avoid redoing work -my $VERSION = '1.002'; +my $VERSION = '1.003'; END { close STDOUT || die "$0: can't close stdout: $!\n"; $? = 1 if $? == 255; # from die } -if (scalar(@ARGV) > 2) { - require Pod::Usage; - Pod::Usage::pod2usage({ -exitval => 1, -verbose => 0 }); +my ($start, $end); +if (scalar(@ARGV) == 0) { + print "Start [default 2]: "; + chomp($start = ); + $start = 2 unless $start =~ m/\S/; + print "End [default " . MAX . "]: "; + chomp($end = ); + $end = MAX unless $end =~ m/\S/; } -chomp(my $start = @ARGV ? $ARGV[0] : ); -my $end = defined $ARGV[1] ? $ARGV[1] : MAX; +elsif (scalar(@ARGV) == 1) { + $start = $ARGV[0]; + $end = MAX; +} +elsif (scalar(@ARGV) == 2) { + $start = $ARGV[0]; + $end = $ARGV[1]; +} +else { + require Pod::Usage; + Pod::Usage::pod2usage({ -exitval => 1, -verbose => 0 }); +} + for ($start, $end) { s/\A\s*\+?(\d{1,10})\Z/$1/ || die "$0: $_: illegal numeric format\n"; $_ > MAX && die "$0: $_: Numerical result out of range\n"; @@ -125,10 +141,9 @@ I. The I value must be at least 0 and not greater than stop. The I value must not be greater than 4294967295. The default value of I is 4294967295. -When the primes utility is invoked with no arguments, I is read -from standard input. I is taken to be 4294967295. The I -value may be preceded by a single C<+>. The I value is -terminated by a non-digit character (such as a newline). +When the primes utility is invoked with no arguments, values are read +from standard input. I and I may be preceded by a single C<+> +character. =head1 BUGS @@ -147,4 +162,3 @@ This program is copyright (c) Jonathan Feinberg and Benjamin Tilly (1999). This program is free and open software. You may use, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same. -