Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > using DateTime object

Reply
Thread Tools

using DateTime object

 
 
aswad
Guest
Posts: n/a
 
      11-29-2006
Hello, I've installed Perl 5.8.8 to use the DateTime module. Because I
need to subtract 2 dates to get the number of days difference. But I
cannot use the DateTime object. In all the examples I've seen, they are
using the new keyword. When I try this I get the following error: Can't
locate object method "new" via package "DateTime" (perhaps you forgot
to load "DateTime"?) at tt.pl line 17.

Can someone tell me what I'm doing wrong. Here is my code. Thanks.

use lib "C:\\Perl\\lib\\ActiveState";
my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
or
my $dt1 = DateTime->now();

 
Reply With Quote
 
 
 
 
aswad
Guest
Posts: n/a
 
      11-29-2006

Sherm Pendley wrote:
> "aswad" <(E-Mail Removed)> writes:
>
> > Hello, I've installed Perl 5.8.8 to use the DateTime module. Because I
> > need to subtract 2 dates to get the number of days difference. But I
> > cannot use the DateTime object. In all the examples I've seen, they are
> > using the new keyword.

>
> "new" isn't a keyword, it's just a method provided by the DateTime module
> that creates a new DateTime object.
>
> > When I try this I get the following error: Can't
> > locate object method "new" via package "DateTime" (perhaps you forgot
> > to load "DateTime"?) at tt.pl line 17.
> >
> > Can someone tell me what I'm doing wrong. Here is my code. Thanks.
> >
> > use lib "C:\\Perl\\lib\\ActiveState";
> > my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
> > or
> > my $dt1 = DateTime->now();

>
> Looks to me like the error already told you precisely what's wrong - you
> forgot to use() the DateTime module.
>
> use DateTime;
>
> Also, unless you installed the module in a non-standard location (you'd
> know if you did), you don't need to specify any additional library paths
> with "use lib". Perl already knows about the standard core and CPAN module
> directories.
>
> You would also benefit from reviewing the basics of modules and their use.
> Have a look at:
>
> perldoc perlmod
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net


Sorry, i do have that statement. I though i had include that line.

use lib "C:\\Perl\\lib\\ActiveState";
use DateTime;

my $dt1 = DateTime->now();

 
Reply With Quote
 
 
 
 
aswad
Guest
Posts: n/a
 
      11-29-2006

Sherm Pendley wrote:
> "aswad" <(E-Mail Removed)> writes:
>
> > Sherm Pendley wrote:
> >> "aswad" <(E-Mail Removed)> writes:
> >>
> >> > When I try this I get the following error: Can't
> >> > locate object method "new" via package "DateTime" (perhaps you forgot
> >> > to load "DateTime"?) at tt.pl line 17.
> >> >
> >> > Can someone tell me what I'm doing wrong. Here is my code. Thanks.
> >> >
> >> > use lib "C:\\Perl\\lib\\ActiveState";
> >> > my $dt1 = DateTime->new(year => 2002, month => 3, day => 1);
> >> > or
> >> > my $dt1 = DateTime->now();
> >>
> >> Looks to me like the error already told you precisely what's wrong - you
> >> forgot to use() the DateTime module.
> >>
> >> use DateTime;

> >
> > Sorry, i do have that statement. I though i had include that line.

>
> Are you saying that you didn't copy-and-paste your real code, as the group
> guidelines suggest you do? Why not? You *have* read the guidelines, haven't
> you?
>
> Anyway, the error message you included above is Perl is telling you that
> you didn't "use DateTime;" before calling its methods. You can think you
> included it all you wish - Perl is telling you that in fact you didn't.
>
> If your real code had actually included "use DateTime;", you would have had
> one of two results - neither of which would be the error message you reported.
>
> If you don't have the DateTime module installed, you would get a "couldn't
> locate DateTime.pm in @INC" error. If you *do* have DateTime installed, and
> your script included "use DateTime;", then you would not be getting the error
> message above.
>
> > use lib "C:\\Perl\\lib\\ActiveState";

>
> I told you before - you don't need "use lib".
>
> > use DateTime;

>
> You have installed the DateTime module, haven't you? It's not a core module,
> it needs to be installed separately. It also needs to be installed correctly.
> Since you're using ActiveState, the best way to install it would be through
> their PPM package manager:
>
> ppm install DateTime
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians: http://wv-www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net


Hi Sherm, thanks for your response. First let me say that I new to Perl
so I not sure of the proper steps to take. First I downloaded and
install activeperl 5.8.8. When I searched for the DateTime.pm file it
was in the C:\Perl\lib\ActiveState directory. That is why I have that
path in the file. If I comment out the use lib line, I get the
following error.

Can't locate DateTime.pm in @INC (@INC contains: C:/Perl/site/lib
C:/Perl/lib .) at C:\Send
ail\TT.pl line 2.
BEGIN failed--compilation aborted at C:\SendMail\TT.pl line 2.

When I ran ppm, I got this error

C:\SendMail>ppm install DateTime
Downloading ActiveState Package Repository packlist...done
Updating ActiveState Package Repository database...done
Syncing site PPM database with .packlists...done
ppm install failed: Can't find any package that provide DateTime

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-30-2006

Quoth "aswad" <(E-Mail Removed)>:
>
> Sherm Pendley wrote:
> > "aswad" <(E-Mail Removed)> writes:
> > > Sherm Pendley wrote:
> > >>
> > >> Looks to me like the error already told you precisely what's wrong - you
> > >> forgot to use() the DateTime module.
> > >>
> > >> use DateTime;
> > >
> > > Sorry, i do have that statement. I though i had include that line.

> >
> > If your real code had actually included "use DateTime;", you would
> > have had one of two results - neither of which would be the error
> > message you reported.

>
> Hi Sherm, thanks for your response. First let me say that I new to Perl
> so I not sure of the proper steps to take. First I downloaded and
> install activeperl 5.8.8. When I searched for the DateTime.pm file it
> was in the C:\Perl\lib\ActiveState directory. That is why I have that
> path in the file.


That module is not DateTime, it is ActiveState:ateTime, which is why
it is in the ActiveState directory.

> If I comment out the use lib line, I get the
> following error.
>
> Can't locate DateTime.pm in @INC (@INC contains: C:/Perl/site/lib
> C:/Perl/lib .) at C:\Send
> ail\TT.pl line 2.
> BEGIN failed--compilation aborted at C:\SendMail\TT.pl line 2.


Because you don't have it installed.

> When I ran ppm, I got this error
>
> C:\SendMail>ppm install DateTime
> Downloading ActiveState Package Repository packlist...done
> Updating ActiveState Package Repository database...done
> Syncing site PPM database with .packlists...done
> ppm install failed: Can't find any package that provide DateTime


Then install it using CPAN.pm, in the usual way:

perl -MCPAN -e"install DateTime"

You will need to download a copy of nmake and put it somewhere on your
PATH if you don't have one already: you can download nmake from
http://download.microsoft.com/downlo...us/nmake15.exe
, and it's probably easiest just to copy it into your c:\perl\bin
directory.

Ben

--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-30-2006

Quoth Ben Morrow <(E-Mail Removed)>:
>
> Then install it using CPAN.pm, in the usual way:
>
> perl -MCPAN -e"install DateTime"


I meant

perl -MCPAN -e"install 'DateTime'"

(with the quotes) of course. I always get tha wrong . I do apologise.

Ben


--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. (E-Mail Removed)
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      11-30-2006
aswad schreef:

> When I ran ppm, I got this error


It works if you have the proper repositories active:

= = = = = = = = = = = = = = = = = = = = = = =
C:\> perl -MDateTime -e1
Can't locate DateTime.pm in @INC (@INC contains: C:/Perl/site/lib C:
BEGIN failed--compilation aborted.

C:\> ppm install DateTime
Downloading ActiveState Package Repository packlist...done
Updating ActiveState Package Repository database...done
Downloading Winnipeg packlist...done
Updating Winnipeg database...done
Downloading RothConsulting packlist...redirect
Downloading RothConsulting packlist...done
[...]
Downloading DateTime-0.34...done
Downloading DateTime-Locale-0.3101...redirect
Downloading DateTime-Locale-0.3101...done
Downloading Params-Validate-0.86...redirect
Downloading Params-Validate-0.86...done
Downloading DateTime-TimeZone-0.56...redirect
Downloading DateTime-TimeZone-0.56...done
Downloading Module-Build-0.2805...redirect
Downloading Module-Build-0.2805...done
Downloading Class-Singleton-1.03...redirect
Downloading Class-Singleton-1.03...done
Unpacking DateTime-0.34...done
Unpacking DateTime-Locale-0.3101...done
Unpacking Params-Validate-0.86...done
Unpacking DateTime-TimeZone-0.56...done
Unpacking Module-Build-0.2805...done
Unpacking Class-Singleton-1.03...done
Generating HTML for DateTime-0.34...done
Generating HTML for DateTime-Locale-0.3101...done
Generating HTML for Params-Validate-0.86...done
Generating HTML for DateTime-TimeZone-0.56...done
Generating HTML for Module-Build-0.2805...done
Generating HTML for Class-Singleton-1.03...done
Installing to site area...done
715 files installed

C:\>
= = = = = = = = = = = = = = = = = = = = = = =

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      11-30-2006
Ben Morrow schreef:
> aswad:


>> When I ran ppm, I got this error
>> ppm install failed: Can't find any package that provide DateTime

>
> Then install it using CPAN.pm, in the usual way:


That is not the usual way when you have AS-Perl on Windows.

First you add repositories and try on from there.

C:\> ppm repo list
+----+------+--------------------------------+
| id | pkgs | name |
+----+------+--------------------------------+
| 1 | 6404 | ActiveState Package Repository |
| 2 | 597 | Winnipeg |
| 3 | 7 | RothConsulting |
+----+------+--------------------------------+
(3 enabled repositories)

C:\Perl\Projects\misc>ppm repo desc 1
Id: 1
Name: ActiveState Package Repository
URL: http://ppm4.activestate.com/MSWin32-...19/package.xml
Enabled: yes
Last-Status: 200 OK
Last-Access: 13 minutes ago
Refresh-In: 37 minutes
Last-Modified: 2 days and 14 hours ago

C:\Perl\Projects\misc>ppm repo desc 2
Id: 2
Name: Winnipeg
URL: http://theoryx5.uwinnipeg.ca/ppms/package.xml
Enabled: yes
Last-Status: 200 OK
Last-Access: 13 minutes ago
Refresh-In: 14 minutes
Last-Modified: 5 hours ago

C:\Perl\Projects\misc>ppm repo desc 3
Id: 3
Name: RothConsulting
URL: http://www.roth.net/perl/packages
Enabled: yes
Last-Status: 200 OK
Last-Access: 13 minutes ago
Refresh-In: 47 minutes

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
aswad
Guest
Posts: n/a
 
      11-30-2006

Dr.Ruud wrote:
> Ben Morrow schreef:
> > aswad:

>
> >> When I ran ppm, I got this error
> >> ppm install failed: Can't find any package that provide DateTime

> >
> > Then install it using CPAN.pm, in the usual way:

>
> That is not the usual way when you have AS-Perl on Windows.
>
> First you add repositories and try on from there.
>
> C:\> ppm repo list
> +----+------+--------------------------------+
> | id | pkgs | name |
> +----+------+--------------------------------+
> | 1 | 6404 | ActiveState Package Repository |
> | 2 | 597 | Winnipeg |
> | 3 | 7 | RothConsulting |
> +----+------+--------------------------------+
> (3 enabled repositories)
>
> C:\Perl\Projects\misc>ppm repo desc 1
> Id: 1
> Name: ActiveState Package Repository
> URL: http://ppm4.activestate.com/MSWin32-...19/package.xml
> Enabled: yes
> Last-Status: 200 OK
> Last-Access: 13 minutes ago
> Refresh-In: 37 minutes
> Last-Modified: 2 days and 14 hours ago
>
> C:\Perl\Projects\misc>ppm repo desc 2
> Id: 2
> Name: Winnipeg
> URL: http://theoryx5.uwinnipeg.ca/ppms/package.xml
> Enabled: yes
> Last-Status: 200 OK
> Last-Access: 13 minutes ago
> Refresh-In: 14 minutes
> Last-Modified: 5 hours ago
>
> C:\Perl\Projects\misc>ppm repo desc 3
> Id: 3
> Name: RothConsulting
> URL: http://www.roth.net/perl/packages
> Enabled: yes
> Last-Status: 200 OK
> Last-Access: 13 minutes ago
> Refresh-In: 47 minutes
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."



Hello, thanks for all the suggestions. But i'm getting a lot of
different approaches. This is what i've done. I've downloaded the
nmake15.exe file and installed it into the c:\perl\bin directory. Then
i downloaded datetime0.35 from CPAN. And installed it into
C:\perl\DateTime-0.35 directory. When i run perl makefile i get the
following:

C:\Perl\DateTime-0.35>perl Makefile.PL
Testing if you have a C compiler
'cl' is not recognized as an internal or external command,
operable program or batch file.

I cannot find a C compiler so I will install a perl-only
implementation

You can force installation of the XS version with

perl Makefile.PL --xs

Checking if your kit is complete...
Looks good
Warning: prerequisite DateTime::Locale 0.31 not found.
Warning: prerequisite DateTime::TimeZone 0.38 not found.
Warning: prerequisite Params::Validate 0.76 not found.
Writing Makefile for DateTime

nmake ran ok. But when i ran nmake test i got a lot of errors, here is
the last line of the output:
1 test and 1 subtest skipped.
Failed 39/41 test scripts, 4.88% okay. 3112/3114 subtests failed, 0.06%
okay.
NMAKE : fatal error U1077: 'C:\WINNT\system32\cmd.exe' : return code
'0xff'
Stop.

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      11-30-2006
aswad schreef:
> Dr.Ruud wrote:
>> Ben Morrow:
>>> aswad:


>>>> When I ran ppm, I got this error
>>>> ppm install failed: Can't find any package that provide DateTime
>>>
>>> Then install it using CPAN.pm, in the usual way:

>>
>> That is not the usual way when you have AS-Perl on Windows.
>> First you add repositories and try on from there.

>
> Hello, thanks for all the suggestions. But i'm getting a lot of
> different approaches.


For ActivePerl on Windows, see the make-route as the last resort.
Just add the Winnipeg (and maybe the Roth) repositories to your ppm and
go from there.
Very convenient.

--
Affijn, Ruud

"Gewoon is een tijger."

 
Reply With Quote
 
aswad
Guest
Posts: n/a
 
      11-30-2006

Dr.Ruud wrote:
> aswad schreef:
> > Dr.Ruud wrote:
> >> Ben Morrow:
> >>> aswad:

>
> >>>> When I ran ppm, I got this error
> >>>> ppm install failed: Can't find any package that provide DateTime
> >>>
> >>> Then install it using CPAN.pm, in the usual way:
> >>
> >> That is not the usual way when you have AS-Perl on Windows.
> >> First you add repositories and try on from there.

> >
> > Hello, thanks for all the suggestions. But i'm getting a lot of
> > different approaches.

>
> For ActivePerl on Windows, see the make-route as the last resort.
> Just add the Winnipeg (and maybe the Roth) repositories to your ppm and
> go from there.
> Very convenient.
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."


This is the only package i have:
C:\> ppm repo list
+--------------------------------------------+
id pkgs name
+----+------+--------------------------------
1 6404 ActiveState Package Repository
+--------------------------------------------+
(1 enabled repository)

C:\>ppm repo desc 1
Id: 1
Name: ActiveState Package Repository
URL: http://ppm4.activestate.com/MSWin32-...19/package.xml
Enabled: yes
Last-Status: 304 Not Modified
Last-Access: 2 hours and 35 minutes ago
Refresh-In: overdue
Last-Modified: 3 days ago

When i run the program, this is what i get:
C:\SendMail>tt.pl
Can't locate Params/Validate.pm in @INC (@INC contains:
C:/Perl/site/lib C:/Perl/lib .) at C
:/Perl/site/lib/DateTime/Duration.pm line 7.
BEGIN failed--compilation aborted at
C:/Perl/site/lib/DateTime/Duration.pm line 7.
Compilation failed in require at C:/Perl/site/lib/DateTime.pm line 51.
BEGIN failed--compilation aborted at C:/Perl/site/lib/DateTime.pm line
51.
Compilation failed in require at C:\SendMail\TT.pl line 2.
BEGIN failed--compilation aborted at C:\SendMail\TT.pl line 2.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [2.4.4] creating a datetime.datetime from an XML xs:dateTime skip@pobox.com Python 2 01-06-2009 01:31 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments