迭代CSV并创建XML文件(Iterating through CSV and creating an XML file)
我试图在Perl中解析CSV文件并将一些列的信息粘贴到XML文件中。 我从未在Perl中做过任何事情,我的想法是将数据存储到数组中,然后在构建数据时将信息从数组中拉出来。
我确定我做错了几件事,因为我没有得到我期望的值,而是看起来像内存中的数组地址(这里是一个例子:
ARRAY(0x35e9360)
。有人可以帮助我并指出一个更好的解决方案吗?
这是有问题的代码:
use Text::CSV; use utf8; use XML::Simple qw(XMLout); use XML::Twig; use File::Slurp; use Encode; &buildXML(); my $csv = Text::CSV->new( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: " . Text::CSV->error_diag(); $csv = Text::CSV->new( { sep_char => '|' } ); $csv = Text::CSV_XS->new( { allow_loose_quotes => 1 } ); my $t = XML::Twig->new( pretty_print => indented ); $t->parsefile('output.xml'); $out_file = "output.xml"; open( my $fh_out, '>>', $out_file ) or die "unable to open $out_file for writing: $!"; my $root = $t->root; #get the root open my $fh, "<:encoding(utf8)", "b.txt" or die "text.txt: $!"; while ( my $row = $csv->getline($fh) ) { my @rows = $row; $builds = $root->first_child(); # get the builds node $xcr = $builds->first_child(); #get the xcr node my $xcrCopy = $xcr->copy(); #copy the xcr node $xcrCopy->paste( after, $xcr ); #paste the xcr node $xcr->set_att( id => "@rows[0]" ); print {$fh_out} $t->sprint(); } $csv->eof or $csv->error_diag();
这是一个测试文件:
ID|Name|Pos 1|a|265 2|b|950 3|c|23 4|d|798 5|e|826 6|f|935 7|g|852 8|h|236 9|i|642
这是由
buildXML()
子构建的XML。<?xml version='1.0' standalone='yes'?> <project> <builds> <xcr id="" name="" pos="" /> </builds> </project>
I am trying to parse a CSV file in Perl and paste the information of some columns into an XML-file. I've never done anything in Perl, and my idea was to store the data into an array and then pull the information out of the array as I build it.
I'm sure I am doing several things wrong, since I am not getting the value I am expecting but instead what looks like the array addresses in the memory (here is an example:
ARRAY(0x35e9360)
.Could somebody help me out and point me to a better solution?
Here is the code in question:
use Text::CSV; use utf8; use XML::Simple qw(XMLout); use XML::Twig; use File::Slurp; use Encode; &buildXML(); my $csv = Text::CSV->new( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: " . Text::CSV->error_diag(); $csv = Text::CSV->new( { sep_char => '|' } ); $csv = Text::CSV_XS->new( { allow_loose_quotes => 1 } ); my $t = XML::Twig->new( pretty_print => indented ); $t->parsefile('output.xml'); $out_file = "output.xml"; open( my $fh_out, '>>', $out_file ) or die "unable to open $out_file for writing: $!"; my $root = $t->root; #get the root open my $fh, "<:encoding(utf8)", "b.txt" or die "text.txt: $!"; while ( my $row = $csv->getline($fh) ) { my @rows = $row; $builds = $root->first_child(); # get the builds node $xcr = $builds->first_child(); #get the xcr node my $xcrCopy = $xcr->copy(); #copy the xcr node $xcrCopy->paste( after, $xcr ); #paste the xcr node $xcr->set_att( id => "@rows[0]" ); print {$fh_out} $t->sprint(); } $csv->eof or $csv->error_diag();
Here is a testfile:
ID|Name|Pos 1|a|265 2|b|950 3|c|23 4|d|798 5|e|826 6|f|935 7|g|852 8|h|236 9|i|642
Here is the XML that is build by the
buildXML()
sub.<?xml version='1.0' standalone='yes'?> <project> <builds> <xcr id="" name="" pos="" /> </builds> </project>
原文:https://stackoverflow.com/questions/38069467
最满意答案
0xe400000000004049
Migth有点大到可以投入。 在x86(32位)AL(8位)是EAX(32位寄存器)的一部分所以我假设(可能是错误的)在64位拱AL上是16位=> 0xFFFF max。
0xe400000000004049
Migth be a little to big to put in al. on x86 (32bits) AL(8bits) is a part of EAX (32bits register) So i assume (maybe wrong) that on 64bit arch AL is 16bits => 0xFFFF max.
相关问答
更多-
0xe400000000004049 Migth有点大到可以投入。 在x86(32位)AL(8位)是EAX(32位寄存器)的一部分所以我假设(可能是错误的)在64位拱AL上是16位=> 0xFFFF max。 0xe400000000004049 Migth be a little to big to put in al. on x86 (32bits) AL(8bits) is a part of EAX (32bits register) So i assume (maybe wrong) that ...
-
我认为这是FPC汇编程序中的一个错误。 您所提供的asm代码是有效的,并且在64位模式下,完全可以像使用32位寄存器一样使用LEA。 英特尔处理器文档对此很清楚。 Delphi 64位内联汇编程序接受此代码。 要解决这个问题,您需要手动组装代码: DQ $265e5a510e8c8d67 在德尔福CPU视图中出现如下: Project1.dpr.12: DQ $265e5a510e8c8d67 0000000000424160 678D8C0E515A5E26 lea ecx,[esi+ecx ...
-
ASM直接呼叫指令(ASM Direct Call Instruction)[2022-09-02]
汇编程序将根据您使用的表达式确定要生成的操作码。 如果你写call foo ,它将是一个近乎相对的呼叫E8 。 如果您call [foo] , call [eax]或call eax ,它将接近间接调用FF (操作码扩展2)。 如果你编写call foo:bar (或者如果汇编程序知道你正在调用远程程序),它将是一个直接的远程调用9A 。 如果你写了call far [foo] ,它将是一个间接的远程调用,也是FF (但操作码扩展3)。 PS:不确定VS的远程调用语法,请参阅文档以获取详细信息。 但是,您通 ... -
由于您提供了原始指令字节,因此这是一个粗略的反汇编: Offset 0: 55 8b ec // not interested in these 3 bytes Offset 3: E8 92 F8 FF FF // a relative call instruction Offset 8: E8 13 00 00 00 // another relative call instruction Offset 13: ... 将00 00 00 13添加到下一条指令( Offset 13 )的 ...
-
跳到指令的中间(Jump to the middle of an instruction)[2023-03-10]
如果你想跳转到jz指令开始的地址减去7个字节,那么你可以用: jz $-7 来自NASM手册 : $计算包含表达式的行开头的程序集位置 请注意, mov和xor指令的大小总共为6个字节,所以在mov开始之前你要跳到1个字节。 要根据你的数字跳,你要使用jz $-4 If you wanted to jump to the address where the jz instruction starts, minus 7 bytes, then you can do that with: jz $-7 Fr ... -
GAS:JMP指令不正确?(GAS: JMP instruction incorrect?)[2023-06-28]
原来在OSX上使用as -L修复了重定位! Turns out using as -L on OSX fixes up the relocation! -
刚检查了Mario 1.1博士,它在启动时复制了hlaB6上的VBlank int例程,然后当VBlank发生时,调用0:01A6的例程,调用OAM DMA传输例程。 在OAM DMA传输期间,CPU只能访问HRAM,因此需要在HRAM中写入一个等待传输完成的短例程。 OAM DMA传输需要160μs,因此您通常会在指定OAM传输源后进行等待这段时间的循环。 这是启动时运行的初始化例程的一部分,它将DMA传输例程复制到HRAM: ... ROM0:027E 0E B6 ld c,B ...
-
MIPS中的JUMP指令(JUMP instruction in MIPS)[2022-10-08]
这种情况真的可能吗? 是的。 引用MIPS32™架构的程序员第二卷:MIPS32™指令集 : 当跳转指令位于256 MB区域的最后一个字中时,它只能分支到包含分支延迟槽的以下256 MB区域。 如果是,它如何解决? 将要跳转的地址加载到寄存器中,然后使用jr指令。 Is this case really possible? Yes, it is. Quoting from MIPS32™ Architecture For Programmers Volume II: The MIPS32™ Instruct ... -
为什么使用ROL指令?(why is ROL instruction is used?)[2023-05-26]
代码以十六进制打印32位值。 ROL指令在这里很方便,因为它允许您以最高到最低的顺序处理半字节。 考虑值0xCAFED00D。 要打印前四个字母,必须按此顺序提取值'C'A''F'和'E'。 EAX = 0xCAFED00D ROL EAX, 4 -> EAX = AFED00DC (lowest nibble is C) ROL EAX, 4 -> EAX = FED00DCA (lowest nibble is A) ROL EAX, 4 -> EAX = ED00DCAF (lo ... -
事实上,这是两个单独的指示: cmp byte ptr [edi],00 add [eax],al 第一个转到edi寄存器指向的存储器地址并从该地址开始取出第一个字节,然后将其与00=0进行比较。 第二条指令通过覆盖所有标志而不依赖于它们来抛弃第一条指令的结果。 它将al (8位寄存器)的内容移动到EAX指向的内存位置,但由于al是eax的最低字节,它就像我们将eax指向的地址中的最低字节复制到指向的内存位置一样地址(我认为没有意义)。 执行前:假设eax=0x00405060 ------------ ...