Skip Menu |

This queue is for tickets about the IO-Prompt CPAN distribution.

Report information
The Basics
Id: 61381
Status: open
Priority: 0/
Queue: IO-Prompt

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: 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
Subject: Re: [rt.cpan.org #61381] Weird behavior with IO::Prompt and numbers
Date: Thu, 16 Sep 2010 16:17:24 +0800
To: bug-IO-Prompt [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Edward, I can't replicate the (weird) behaviour you're seeing when I run your sample code on my own system under Perl 5.10.0. That makes it tough to diagnose the problem. About the only possibility that come to mind is that IO::Prompt returns an object (with a stringification overloading), not a simple string. It is *possible* that Date::Calc::Day_of_Week() doesn't like to be fed objects. In which case, you could try changing the line: my $wday = Day_of_Week($year,$month,$day); to: my $wday = Day_of_Week("$year","$month","$day"); to ensure that you're feeding it actual strings (instead of stringifiable objects). Let me know if that helps. If it does solve the problem, then (arguably) the bug is in Date::Calc...but all that really matters is that we solved your problem. :-) Meanwhile, I'll keep thinking about what else might be causing your difficulties. All the best, Damian
Subject: Re: [rt.cpan.org #61381] Weird behavior with IO::Prompt and numbers
Date: Thu, 16 Sep 2010 03:15:33 -0600
To: bug-IO-Prompt [...] rt.cpan.org
From: Edward Doolittle <edward.doolittle [...] gmail.com>
Hi Damian, Stringifying the stringifiable objects as per your suggestion works for me. Thanks! The non-deterministic nature of the bug was rather surprising ... I guess it might have something to do with the index of the memory location of the object. Should I report a bug to Date::Calc? Edward On Thu, Sep 16, 2010 at 2:18 AM, damian@conway.org via RT < bug-IO-Prompt@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=61381 > > > Hi Edward, > > I can't replicate the (weird) behaviour you're seeing when I run your > sample code on my own system under Perl 5.10.0. > > That makes it tough to diagnose the problem. About the only possibility > that come to mind is that IO::Prompt returns an object (with a > stringification overloading), not a simple string. It is *possible* that > Date::Calc::Day_of_Week() doesn't like to be fed objects. In which case, > you could try changing the line: > > my $wday = Day_of_Week($year,$month,$day); > > to: > > my $wday = Day_of_Week("$year","$month","$day"); > > to ensure that you're feeding it actual strings (instead of > stringifiable objects). > > Let me know if that helps. If it does solve the problem, then (arguably) > the bug is in Date::Calc...but all that really matters is that we solved > your problem. :-) > > Meanwhile, I'll keep thinking about what else might be causing your > difficulties. > > All the best, > > Damian > >
-- 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
Subject: Re: [rt.cpan.org #61381] Weird behavior with IO::Prompt and numbers
Date: Fri, 17 Sep 2010 04:35:12 +0800
To: bug-IO-Prompt [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Edward, Glad to hear that... Show quoted text
> Stringifying the stringifiable objects as per your suggestion works for me.
I suspect that you're right: the inconsistent results might have been caused by Date::Calc using the object addresses, rather than the object numerification. This may be due to the fact that the module is implemented in C, not Perl (i.e. the C functions may be assuming they are passed day/month/year numbers, but not actually checking that, and hence just using the object references directly as if they were numbers, instead of invoking the correct numerical overloading.) If that is indeed the case, then it might be considered a bug in Date::Calc, or at least an omission from its documentation. On the other hand, since it worked fine on my Mac under 5.10.0, it might also be a bug in Perl 5.10.1, or in the C compiler on Debian. Show quoted text
> Should I report a bug to Date::Calc?
I think you should report the *situation* to Date::Calc and let the maintainer decide if it's a bug (or a feature ;-) All the best, Damian PS: If your using 5.10 or later and you find IO::Prompt useful, you might also be interested in its successor: IO::Prompter. It has a slightly different interface and feature set, but some nice additions you might find useful, not the least of which is that its feature set is fully documented!