The while test on the value of days is made after the conversion to seconds is done so when you enter q you are trying to convert it to seconds. you could do a few things, here is one that keeps a while loop...
#!/usr/local/bin/perl -w use strict; while (1) { print "Please enter a single positive integer that represents a number of da +ys, that you wish to convert into seconds. ,(enter q to quit): "; chomp (my $days = <STDIN>); $days =~ s/\+//; # allow them to enter +12 if ($days eq "q") { last; } elsif (($days =~ /[^\d]/) or ($days eq "")) { # days contains an non digit character or is empty print "\n!!! You must enter a positive integer.\n\n"; } else { my $seconds = $days * 86400; my $plural = ($days == 1) ? '' : 's'; print "\n$days day$plural = $seconds seconds.\n\n"; } } print "Goodbye\!\n\n";
} elsif (($days =~ /[^\d]/) or (not $days)) {
Cheers,
R.
In reply to Re: String/Numeric Manipulation
by Random_Walk
in thread String/Numeric Manipulation
by Ms. T.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |