首页 \ 问答 \ 迭代CSV并创建XML文件(Iterating through CSV and creating an XML file)

迭代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
更新时间:2022-11-30 19:11

最满意答案

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 ...
  • 汇编程序将根据您使用的表达式确定要生成的操作码。 如果你写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 )的 ...
  • 如果你想跳转到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 ...
  • 原来在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 ...
  • 这种情况真的可能吗? 是的。 引用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 ...
  • 代码以十六进制打印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 ------------ ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)