Skip Menu |

This queue is for tickets about the Date-Calc CPAN distribution.

Report information
The Basics
Id: 61444
Status: new
Priority: 0/
Queue: Date-Calc

People
Owner: Nobody in particular
Requestors: edward.doolittle [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Strange interaction between Date::Calc and IO::Prompt
Date: Sat, 18 Sep 2010 01:06:45 -0600
To: bug-Date-Calc [...] rt.cpan.org
From: Edward Doolittle <edward.doolittle [...] gmail.com>
Hi, Below you will find a short Perl program to read in a date from the terminal and spit out the day of the week, and its output, which is very strange to me. With the help of Damian Conway of IO::Prompt, I was able to discover that the behavior of the program is normal, stable, and as expected if I put quotes around the arguments to the $year, $month, and $day arguments to Day_of_Week (uncomment the commented line of the program), although Damian was not able to reproduce the behavior on his machine. We suspect that the problem is related to the return value of prompt() being a stringifiable object, not a string; perhaps Day_of_Week is somehow using the pointer to the object instead of its stringification, or something like that. $ perl -v This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi (with 46 registered patches, see perl -V for more detail) $ perl -e 'use Date::Calc; print Date::Calc::Version(),"\n";' 6.3 $ uname -a Linux yoyodyne 2.6.30-2-686 #1 SMP Fri Dec 4 00:53:20 UTC 2009 i686 GNU/Linux $ cat /etc/debian_version squeeze/sid $ ./dow.pl Month number: 9 Day number: 18 Year number: 2010 September 18, 2010 was a Sunday Month number: 9 Day number: 18 Year number: 2010 September 18, 2010 was a Friday Month number: 9 Day number: 18 Year number: 2010 September 18, 2010 was a Monday Month number: 9 Day number: 18 Year number: 2010 September 18, 2010 was a Wednesday Month number: ^D $ $ cat ./dow.pl #!/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{\A [1-9] | 1[0-2] \z}xms; Readonly my $DAY_REGEX => qr{\A [1-9] | [1-2][0-9] | 3[0-1] \z}xms; Readonly my $YEAR_REGEX => qr{\A [1-9][0-9]* \z}xms; 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 positive 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; #my $wday = Day_of_Week("$year","$month","$day"); my $wday = Day_of_Week($year,$month,$day); print "$mons[$month] $day, $year was a $days[$wday]\n\n"; last DATE if ($month==6 && $day==6 && $year==6); } -- Edward Doolittle Associate Professor of Mathematics Department of Science First Nations University of Canada 1 First Nations Way, Regina SK S4S 7K2 (306) 537-9631