我收到以下错误:
Can't locate object method "now" via package "Datetime" (perhaps you forgot to load "Datetime"?) at ../scripts/dateTimeTest.pl line 4.
对于这个脚本:
#!/usr/bin/perl -w
require DateTime;
my $dt = Datetime->now;
但是,以下命令行程序可以运行:
perl -e 'require DateTime; my $dt = DateTime->now'
我错过了什么?
答案 0 :(得分:9)
Perl区分大小写。变化:
my $dt = Datetime->now;
为:
my $dt = DateTime->now;
你的单行内容是正确的,但不在你的剧本中。