Stephen Rasku
Stephen Rasku

Reputation: 2682

Can't locate object method "now" via package "Datetime"

I am getting the following error:

Can't locate object method "now" via package "Datetime" (perhaps you forgot to load "Datetime"?) at ../scripts/dateTimeTest.pl line 4.

For this script:

#!/usr/bin/perl -w

require DateTime;
my $dt = Datetime->now;

However, the following command-line program works:

perl -e 'require DateTime; my $dt = DateTime->now'

What am I missing?

Upvotes: 0

Views: 1618

Answers (1)

toolic
toolic

Reputation: 62227

Perl is case-sensitive. Change:

my $dt = Datetime->now;

to:

my $dt = DateTime->now;

You got the case right in your one-liner, but not in your script.

Upvotes: 9

Related Questions