|
Posted by sstark on May 8, 2005, 6:10 pm
Please log in for more thread options
Hello, I'm having trouble with Date::Simple. Here's my code:
## begin
use Date::Simple (':all');
my($date) = &Date::Simple::today();
read_file('myfile.txt'); # grabs $ENTRYYEAR, $ENTRYMONTH, $ENTRYDATE
from myfile.txt
my($deadline) = &Date::Simple::ymd($ENTRYYEAR, $ENTRYMONTH,
$ENTRYDATE);
my($diff) = (date($deadline) - date($date));
## end
This produces the output:
Can't subtract a date from a non-date at ./ann.pl line 836
If I comment out the subtraction and print the variables, they look
fine to me:
## comment and print
#my($diff) = (date($deadline) - date($date));
print "Y: $ENTRYYEAR; M: $ENTRYMONTH; D: $ENTRYDATEn";
##
Output:
Y: 2005; M: 05; D: 10
If I assign the 3 variables instead of using read_file(), it works
fine:
## begin code
use Date::Simple (':all');
my($date) = &Date::Simple::today();
#read_file('myfile.txt'); # grabs $ENTRYYEAR, $ENTRYMONTH, $ENTRYDATE
from myfile.txt
my($ENTRYYEAR) = "2005";
my($ENTRYMONTH) = "05";
my($ENTRYDATE) = "10";
my($deadline) = &Date::Simple::ymd($ENTRYYEAR, $ENTRYMONTH,
$ENTRYDATE);
my($diff) = (date($deadline) - date($date));
print "diff: $diffn";
## end
Output:
diff: 2
Can anyone tell me what I'm doing wrong?
thanks,
Scott
|
|
Posted by Gunnar Hjalmarsson on May 9, 2005, 3:38 am
Please log in for more thread options
sstark wrote:
> Hello, I'm having trouble with Date::Simple. Here's my code:
>
> ## begin
> use Date::Simple (':all');
> my($date) = &Date::Simple::today();
> read_file('myfile.txt'); # grabs $ENTRYYEAR, $ENTRYMONTH, $ENTRYDATE
> from myfile.txt
> my($deadline) = &Date::Simple::ymd($ENTRYYEAR, $ENTRYMONTH,
> $ENTRYDATE);
> my($diff) = (date($deadline) - date($date));
> ## end
>
> This produces the output:
> Can't subtract a date from a non-date at ./ann.pl line 836
>
> If I comment out the subtraction and print the variables, they look
> fine to me:
>
> ## comment and print
> #my($diff) = (date($deadline) - date($date));
> print "Y: $ENTRYYEAR; M: $ENTRYMONTH; D: $ENTRYDATEn";
> ##
>
> Output:
> Y: 2005; M: 05; D: 10
For a safer way to identify possible characters besides numbers you can
for instance do:
print "[$ENTRYYEAR-$ENTRYMONTH-$ENTRYDATE]n";
> If I assign the 3 variables instead of using read_file(), it works
> fine:
Then you know that the problem lies in your read_file() function, right?
> Can anyone tell me what I'm doing wrong?
You are not showing us the read_file() function.
(A wild guess would be that the $ENTRYDATE variable needs to be chomp()ed.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
|
|
Posted by sstark on May 9, 2005, 8:12 am
Please log in for more thread options
Hi Gunnar, thanks for the reply. Your comments helped me discovered the
problem -- one of my data files had an invalid date, i.e. June 31,
2005. Looks like Date::Simple was smart enough to see it as a bogus
date, or, rather, see it as a "non-date" which I assume means it
thought it was just a string.
(sheepishly) thanks
Scott
|
| Similar Threads | Posted | | RRD confusion | June 20, 2005, 5:36 pm |
| File::Stream confusion | November 14, 2005, 4:17 pm |
| Date::MSAccess V 1.01 | July 29, 2004, 7:15 am |
| problems with Date-Calc | July 8, 2004, 3:09 pm |
| Date::Calc install | September 8, 2004, 10:02 am |
| perl date manipulation | October 21, 2004, 5:02 pm |
| ANNOUNCE: Date::MSAccess V 1.02 | February 14, 2005, 10:44 am |
| Date::Calc Problem | February 9, 2006, 12:25 am |
| military time with Date::Calc | June 9, 2005, 1:09 am |
| Date and time--recommended module? | November 8, 2006, 3:41 pm |
|