Subject: | Weird behavior with IO::Prompt and numbers |
Date: | Wed, 15 Sep 2010 22:48:59 -0600 |
To: | bug-io-prompt [...] rt.cpan.org |
From: | Edward Doolittle <edward.doolittle [...] gmail.com> |
Hi,
I'm using IO::Prompt to gather some information about dates at the
terminal. Below is a transcript of the output, followed by the program. As
you can see the calculated weekday for 2010-9-15 bounces all over the place,
as if there were some weird invisible garbage in the $day, $month, and/or
$year variables. However, if I uncomment the commented line in my program
which just injects numbers into those variables rather than reads them from
the command line, the output is normal, consistent, and correct as
expected. I concluded that the problem is with IO::Prompt and not with
Date::Calc. I'm running
This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi
(with 46 registered patches, see perl -V for more detail)
on Debian Linux and version 0.997001 of IO::Prompt. Can you tell me what
I'm doing wrong, or what is wrong with IO::Prompt?
Edward
Month number: 9
Day number: 15
Year number: 2010
year is 2010, month is 9, day is 15, wday is 6
September 15, 2010 was a Saturday
Month number: 9
Day number: 15
Year number: 2010
year is 2010, month is 9, day is 15, wday is 3
September 15, 2010 was a Wednesday
Month number: 9
Day number: 15
Year number: 2010
year is 2010, month is 9, day is 15, wday is 6
September 15, 2010 was a Saturday
Month number: 9
Day number: 15
Year number: 2010
year is 2010, month is 9, day is 15, wday is 2
September 15, 2010 was a Tuesday
Month number: ^D dolittle@yoyodyne:~/Courses/math101$
#!/usr/bin/perl
use strict;
use warnings;
use Readonly;
use Date::Calc qw( Day_of_Week );
use IO::Prompt;
my @days = qw( Error Monday Tuesday Wednesday
Thursday Friday Saturday Sunday
);
my @mons = qw( Error January February March
April May June July
August September October November
December
);
Readonly my $MONTH_PROMPT => q{Month number: };
Readonly my $DAY_PROMPT => q{Day number: };
Readonly my $YEAR_PROMPT => q{Year number: };
Readonly my $MONTH_REGEX => qr/ [1-9] | 1[0-2] /x;
Readonly my $DAY_REGEX => qr/ [1-9] | [1-2][0-9] | 3[0-1] /x;
Readonly my $YEAR_REGEX => qr/ [1-9][0-9]* /x;
Readonly my $MONTH_REPROMPT => q{(must be in range 1..12) Month number: };
Readonly my $DAY_REPROMPT => q{(must be in range 1..31) Day number: };
Readonly my $YEAR_REPROMPT => q{(must be positve integer) Year number: };
DATE:
while (1) {
my $month
= prompt( $MONTH_PROMPT, -req => { $MONTH_REPROMPT => $MONTH_REGEX
});
last DATE if !$month;
my $day
= prompt( $DAY_PROMPT, -req => { $DAY_REPROMPT => $DAY_REGEX }
);
last DATE if !$day;
my $year
= prompt( $YEAR_PROMPT, -req => { $YEAR_REPROMPT => $YEAR_REGEX }
);
last DATE if !$year;
last DATE if ($month==6 && $day==6 && $year==66);
#($year,$month,$day) = (2010,9,15);
my $wday = Day_of_Week($year,$month,$day);
print "year is $year, month is $month, day is $day, wday is $wday\n";
print "$mons[$month] $day, $year was a $days[$wday]\n\n";
}
--
Edward Doolittle
Associate Professor of Mathematics
Department of Science
First Nations University of Canada
1 First Nations Way, Regina SK S4S 7K2
+1 (306) 537-9631