这个 Perl 崩溃意味着什么?
有人能告诉我这是什么意思吗?
if (not defined $config{'crontab'}) {
die "no crontab defined!";
}
我想打开一个文件 crontab.txt 但 perl 脚本在这一行崩溃了,而且我真的不知道任何 perl。
编辑1
它是这样的:
sub main()
{
my %config = %{getCommandLineOptions()};
my $programdir = File::Spec->canonpath ( (fileparse ( Win32::GetFullPathName($PROGRAM_NAME) ))[1] );
my $logdir = File::Spec->catdir ($programdir, 'logs');
$logfile = File::Spec->catfile ($logdir, 'cronw.log');
configureLogger($logfile);
$log = get_logger("cronw::cronService-pl");
# if --exec option supplied, we are being invoked to execute a job
if ($config{exec}) {
execJob(decodeArgs($config{exec}), decodeArgs($config{args}));
return;
}
my $cronfile = $config{'crontab'};
$log->info('starting service');
$log->debug('programdir: '.$programdir);
$log->debug('logfile: '.$logfile);
if (not defined $config{'crontab'}) {
$log->error("no crontab defined!\n");
die "no crontab defined!";
# fixme: crontab detection?
}
$log->debug('crontab: '.$config{'crontab'});
我正在尝试加载这个“crontab.txt”文件...
sub getCommandLineOptions()
{
my $clParser = new Getopt::Long::Parser config => ["gnu_getopt", "pass_through"];
my %config = ();
my @parameter = ( 'crontab|cronfile=s',
'exec=s',
'args=s',
'v|verbose'
);
$clParser->getoptions (\%config, @parameter);
if (scalar (@ARGV) != 0) { $config{'unknownParameter'} = $true; }
return \%config;
}
可能我必须给脚本一个参数
Can someone tell me what this means?
if (not defined $config{'crontab'}) {
die "no crontab defined!";
}
I want to open a file crontab.txt but the perl script crashes at this line and I don't really know any perl.
EDIT 1
It goes like this:
sub main()
{
my %config = %{getCommandLineOptions()};
my $programdir = File::Spec->canonpath ( (fileparse ( Win32::GetFullPathName($PROGRAM_NAME) ))[1] );
my $logdir = File::Spec->catdir ($programdir, 'logs');
$logfile = File::Spec->catfile ($logdir, 'cronw.log');
configureLogger($logfile);
$log = get_logger("cronw::cronService-pl");
# if --exec option supplied, we are being invoked to execute a job
if ($config{exec}) {
execJob(decodeArgs($config{exec}), decodeArgs($config{args}));
return;
}
my $cronfile = $config{'crontab'};
$log->info('starting service');
$log->debug('programdir: '.$programdir);
$log->debug('logfile: '.$logfile);
if (not defined $config{'crontab'}) {
$log->error("no crontab defined!\n");
die "no crontab defined!";
# fixme: crontab detection?
}
$log->debug('crontab: '.$config{'crontab'});
And I'm trying to load this 'crontab.txt' file...
sub getCommandLineOptions()
{
my $clParser = new Getopt::Long::Parser config => ["gnu_getopt", "pass_through"];
my %config = ();
my @parameter = ( 'crontab|cronfile=s',
'exec=s',
'args=s',
'v|verbose'
);
$clParser->getoptions (\%config, @parameter);
if (scalar (@ARGV) != 0) { $config{'unknownParameter'} = $true; }
return \%config;
}
Probably I have to give the script an argument
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会这么说。
$ script --cronfile=somefile
I would say so.
$ script --cronfile=somefile
该代码查看哈希
%config
中是否存在键'crontab'
。如果不是,则调用die
并终止。如果这不是您期望发生的情况,那么在脚本的其他地方应该有一些东西正在设置
$config{'crontab'}
,但目前还没有足够的您问题中的信息以确定可能是什么。That code looks to see whether there is a key
'crontab'
in the hash%config
. If not, then it callsdie
and terminates.If that's not what you expect to happen, then somewhere else in your script there should be something that is setting
$config{'crontab'}
, but there is not currently enough information in your question to determine what that might be.可能 crontab.txt 的文件路径应该在 %config 哈希中,由“crontab”键指向,但不存在!如果是这样,一个肮脏的解决方案可以是:
但这可能不起作用,因为有类似 $config{'prefix'} 的东西,而您将尝试打开的是由两者串联表示的路径,或者只是因为在 $config{ 'crontab'} 应该是除完整路径之外的任何其他值!
Probably the file path of crontab.txt is expected in %config hash, pointed by the 'crontab' key, but isn't there! If so, a DIRTY solution CAN BE:
but this may not work because there is something like $config{'prefix'} and what you will try to open is the path represented by the concatenation of both, or just because in $config{'crontab'} is expected any other value than full path!