这个 Perl 崩溃意味着什么?

发布于 2024-12-18 11:37:23 字数 1664 浏览 0 评论 0原文

有人能告诉我这是什么意思吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜是你 2024-12-25 11:37:23

也许我必须给脚本一个参数

我会这么说。

$ script --cronfile=somefile

Probably I have to give the script an argument

I would say so.

$ script --cronfile=somefile

猛虎独行 2024-12-25 11:37:23

该代码查看哈希 %config 中是否存在键 'crontab'。如果不是,则调用die并终止。

如果这不是您期望发生的情况,那么在脚本的其他地方应该有一些东西正在设置$config{'crontab'},但目前还没有足够的您问题中的信息以确定可能是什么。

That code looks to see whether there is a key 'crontab' in the hash %config. If not, then it calls die 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.

没有心的人 2024-12-25 11:37:23

可能 crontab.txt 的文件路径应该在 %config 哈希中,由“crontab”键指向,但不存在!如果是这样,一个肮脏的解决方案可以是:

$config{'crontab'}='FULLPATH/crontab.txt';
#if (not defined $config{'crontab'}) {
#   die "no crontab defined!";
#}

但这可能不起作用,因为有类似 $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:

$config{'crontab'}='FULLPATH/crontab.txt';
#if (not defined $config{'crontab'}) {
#   die "no crontab defined!";
#}

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文