2011-11-30 144 views
0

有人能告訴我這是什麼意思?這個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; 
} 

也許我得給腳本一個參數

+0

你會得到什麼錯誤? 「 – BoltClock

+0

」no crontab defined!at cronService.pl line 410.「 –

+2

你的代碼調用名爲'getCommandLineOptions()'的東西,並將其分配給'%config'。這個名字強烈暗示可能你缺少的'crontab'設置與你預期提供的一些命令行參數有關。 –

回答

4

也許我得給腳本參數

我會這麼說。

$ script --cronfile=somefile

2

該代碼查看散列%config中是否有密鑰'crontab'。如果不是,則它調用die並終止。

如果這不是你期望發生,那麼別的地方在你的腳本應該有一些是設置$config{'crontab'}什麼,但目前還沒有足夠的信息,在你的問題,以確定哪些可能是。

+0

我認爲這是事實,但是因爲Perl對我來說就像克林貢...我只想告訴腳本在哪裏找到文件'crontab.txt' –

+0

那麼,你可以添加一行'$ config {'crontab' } =「/path/to/crontab.txt」;'在代碼之前,看看是否有幫助。 –

+0

my $ cronfile = $ config {'crontab'}; –

1

可能是crontab.txt的文件路徑在%config hash中,'crontab'鍵指向,但不在那裏!如果是這樣,一個骯髒的解決方案可能是:

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

但這可能無法工作,因爲有類似$配置{「前綴」}和你將嘗試打開是由兩個級聯而成的路徑,或者僅僅是因爲在$ config {'crontab'}期望的是除完整路徑以外的任何其他值!