2012-11-07 3 views
0

내가 쓰고있는 스크립트를 찾을 수 있습니다. 내 질문은 스크립트 아래에있다. 내가 얻고Perl을 사용하여 XML에 쓰는 데 문제가 있습니다.

use XML::Writer; 
use IO; 

@sortedPLATFORMS = qw(win32_x86 win64_x64 linux_x86 linux_x64 solaris_sparc solaris_sparcv9 aix_rs6000 aix_rs6000_64 hpux_pa-risc hpux_ia64); 
@STARTS = qw(wdf_22_00 wdf_23_00 wdf_00_00 wdf_01_00 wdf_02_00); 

my @waitFors; 

my $thisPlatform; 
my $thisMachine; 
my $thisTask; 
my $thisBuild; 
my $thisCMD; 
my $thisWaitFor; 


foreach my $start(@STARTS) 
{ 
    my $jobFile = "jobs/$start.txt"; 
    my $doc = new IO::File(">$start.xml", 'w'); 
    my $writer = new XML::Writer(OUTPUT => $doc) or die "Cannot open file"; 
    $writer->xmlDecl("UTF-8"); #XML declaration 
    $writer->startTag("$start"); 

    if(open(JOB_FILE,$jobFile)) 
    { 
    while(<JOB_FILE>) 
    { 
     chomp; 
     s-^\s+$--; 
     next unless($_); 
     next if(/^\;/); 
     next if(/\[config\]/); 
     next if(/event_dir\s+\=\s+(.+?)$/); 

     if(/\[(.+?)\]/) 
     { 
      getInfos(); 
     } 
     elsif(/^\s+waitfor\s+\=\s+(.+?)$/) 
     { 
      $thisWaitFor = $1; 
      push(@waitFors, "$thisWaitFor"); 
     } 
     elsif(/^\s+command\s+\=\s+(.+?)$/) 
     { 
      $thisCMD = $1; 
      writeXML(); 
      @waitFors =(); 
     }  
    } 
} 
else 
{ 
    print "something is wrong"; 
} 

$writer->endTag(); 
    $writer->end(); 
    $doc->close(); 
close JOB_FILE; 
} 

오류 :

방법 "characters"writeXML() 서브에서하는 $writer->characters("\n\n"); 라인이다
Can't call method "characters" on an undefined value at createMachineList.pl 
line 96, <JOB_FILE> line 13. 

.

나는 writeXML()에 전달 된 정의되지 않은 값이 있다는 것을 알고 있지만 그 이유를 이해하지 못합니다.

아무도이 문제에 관해 밝힐 수 있습니까?

당신은 루프 내부 my $writer를 선언 sSmacKk

답변

4

, 감사합니다. 함수는 루프 외부에서 선언됩니다. 따라서이 함수에는 변수에 대한 액세스 권한이 없습니다. 인수로 전달하거나 전역으로 설정하십시오 (권장하지 않음). strictwarnings을 사용하고 있습니까?

+0

지적 해 주셔서 감사합니다 ... 때로는 뒤로 물러나서 신선한 모양을 취해야합니다. – sSmacKk

관련 문제