using DateTime object

A

aswad

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();
 
A

aswad

Sherm said:
"new" isn't a keyword, it's just a method provided by the DateTime module
that creates a new DateTime object.


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--

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();
 
A

aswad

Sherm said:
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.


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


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--

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
 
B

Ben Morrow

Quoth "aswad said:
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::DateTime, 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/download/vc15/patch/1.52/w95/en-us/nmake15.exe
, and it's probably easiest just to copy it into your c:\perl\bin
directory.

Ben
 
B

Ben Morrow

Quoth Ben Morrow said:
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
 
D

Dr.Ruud

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:\>
= = = = = = = = = = = = = = = = = = = = = = =
 
D

Dr.Ruud

Ben Morrow schreef:
aswad:

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-x86/5.8/819/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
 
A

aswad

Dr.Ruud said:
Ben Morrow schreef:

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-x86/5.8/819/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


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.
 
D

Dr.Ruud

aswad schreef:
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.
 
A

aswad

Dr.Ruud said:
aswad schreef:

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.

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-x86/5.8/819/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.
 
D

Dr.Ruud

aswad schreef:
Dr.Ruud:

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

That is not a package but a repository.

Like I said two times before now, add more repositories. See "perldoc
ppm" for how to do that, or use the new GUI-ppm, which has a form under
Edit/Preferences for adding repositories. For the details of the
repositories to add, see an earlier posting.

(Please only quote relevant text, so no signatures or any other text
from previous postings that is no longer relevant, so certainly remove
this text and the following sig if you need to reply.)
 
S

Steve K.

Sherm said:
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?

This common short sightedness keeps coming back again and again around
here. I have looked and looked and I don't see any posting for a
guideline in the correct listing for this group from my news server.

If he is news to this group, I think it is a little unfair to expect him
to have read something he may not have any knowledge about.

It's like expecting someone who enters a building to read the directory,
when the directory is down a couple of hallways, constantly changing
it's location (just like you never really know where and if you'll have
the guideline posting, if it's still being posted, in your spool.)

I could understand this sort of attitude on a medium such as a web forum
where FAQs are either global fixed links at the top of the of the board,
or as "pinned" FAQ postings for a given forum.

But in a medium such as NNTP where such postings are hit and miss, it's
just plain asinine to think everyone automatically knows of and even is
able to see them.
 
A

aswad

Dr.Ruud said:
Dr.Ruud schreef:


But also consider this:

"Getting Fed Up with ActiveState"
http://www.perlmonks.org/?node_id=587162

Well thanks for all the different suggestions, but done have worked.
I'm surprised that this is so difficult. What is the difference between
ActiveState DateTime and DateTime from CPAN. If i already have the
DateTime module from ActiveState why can't i just use that?
 
A

aswad

Sherm said:
You're confusing two completely separate issues here.

Package names are *very* relevant. ActiveState::DateTime is not the same
module as DateTime. The differences in the two are not at all related to the
means used to install them.

PPM and CPAN are simply two different installation mechanisms. The procedure
for using them to install modules differs, but once the DateTime module has
been installed, the means you used to install it makes zero different in how
it's used in your scripts.


You don't. You have the ActiveState::DateTime module, not the DateTime module.
Package names are important!


Maybe you can. Have you read the docs for ActiveState::DateTime to see if
it will do what you want to do?

sherm--

Hi Sherm, thanks for the information. I took a look at the
documentation on the ActiveState web site. But couldn't find anything
on DateTime. Or maybe I wasn't looking under the right section.
 
J

Jim Gibson

Hi Sherm, thanks for the information. I took a look at the
documentation on the ActiveState web site. But couldn't find anything
on DateTime. Or maybe I wasn't looking under the right section.

Perl comes with its own documentation, as do most modules. Type

perldoc ActiveState::DateTime

at a command-line prompt. I have also read on this newsgroup that the
ActiveState Perl installation comes with HTML documentation, so it is
likely that AS has provided the documentation for this module. Look
under the 'Start' menu (can't be much more help than that because I do
not have access to an AS Perl installation).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top