Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Perl编写xml时遇到问题_Xml_Perl_Compiler Errors_Xmlwriter - Fatal编程技术网

使用Perl编写xml时遇到问题

使用Perl编写xml时遇到问题,xml,perl,compiler-errors,xmlwriter,Xml,Perl,Compiler Errors,Xmlwriter,下面你可以找到我正在写的剧本。我的问题在剧本下面 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_

下面你可以找到我正在写的剧本。我的问题在剧本下面

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;
}
使用XML::Writer;
使用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);
@启动=qw(wdf_22_00 wdf_23_00 wdf_00 wdf_01_00 wdf_02_00);
我的@waitFors;
我的$this平台;
我的机器;
我的任务;
我的$thisBuild;
我的$thisCMD;
我的$thiswitfor;
foreach my$start(@STARTS)
{   
my$jobFile=“jobs/$start.txt”;
my$doc=new IO::File(“>$start.xml”,“w”);
我的$writer=new XML::writer(OUTPUT=>$doc)或死“无法打开文件”;
$writer->xmlDecl(“UTF-8”)#XML声明
$writer->startTag($start”);
if(打开(作业文件,$jobFile))
{
while()
{
咀嚼;
s-^\s+$--;
下一个除非($);
下一个if(/^\;/);
下一个if(/\[config\]/);
下一个if(/event\u dir\s+\=\s+(.+?)$/);
如果(/\[(.+?)\]/)
{
getInfos();
}
elsif(/^\s+waitfor\s+\=\s+(.+?)$/)
{
$thisWaitFor=$1;
推送(@waitFors,“$thisWaitFor”);
}
elsif(/^\s+命令\s+\=\s+(.+?)$/)
{
$thisCMD=$1;
writeXML();
@waitFors=();
}       
}
}
其他的
{
打印“有问题”;
}
$writer->endTag();
$writer->end();
$doc->close();
关闭作业文件;
}
我得到的错误是:

    Can't call method "characters" on an undefined value at createMachineList.pl
 line 96, <JOB_FILE> line 13.
无法对createMachineList.pl上未定义的值调用方法“characters”
第96行,第13行。
其中方法
“characters”
$writer->characters(“\n\n”)行,该行来自
writeXML()
sub

我知道有一个未定义的值传递给
writeXML()
,但我不明白为什么

有谁能解释一下这个问题吗

谢谢,,
sSmacKk

您在循环中声明了
my$writer
。函数在循环外部声明。因此,函数无法访问变量。要么将其作为参数传递,要么将其设置为全局(不推荐)。您是否在使用
strict
warnings

您在循环中声明了
my$writer
。函数在循环外部声明。因此,函数无法访问变量。要么将其作为参数传递,要么将其设置为全局(不推荐)。您是否使用了
strict
warnings

感谢您指出。。。有时候你需要后退一步,重新审视一下谢谢你指出了这一点。。。有时候你需要后退一步,重新审视