如何在不导入xml解析器模块的情况下将xml数据传递到perl脚本? [英] how to pass xml data to perl script without import xml parser module?

查看:111
本文介绍了如何在不导入xml解析器模块的情况下将xml数据传递到perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

需要在各种服务器(所有AIX UNIX)上运行perl脚本. perl脚本需要xml脚本中的数据.只需读取数据,无需执行写入或其他修改操作. xml脚本的内容有时会更改.

A perl script need to be run on various servers (all AIX unix). The perl script need the data from a xml script. Just read the data, no write or other modify action. The contents of xml script changes sometimes.

问题:

我不能在perl脚本中使用xml解析器模块(例如XML :: LibXML),因为aix服务器没有安装该模块,并且我不想一个接一个地安装它们.有很多aix服务器.

I can not use xml parser module (like XML::LibXML) in the perl script, since the aix server does not install the module, and I don't want to install them one by one. There are many aix servers.

有一台linux服务器(红帽linux)安装了xml模块.每个aix服务器都可以访问它.

There is one linux server(red hat linux) that installed the xml module. And every aix server can access it.

有什么方法可以将xml数据传递到perl脚本,而无需xml模块?像先在Linux上解析xml,然后将输出作为输入传递到perl脚本一样?不知道它是否可行.

Any way to pass the xml data to the perl script, while do not require the xml module? Like first parse the xml on the linux, then pass the output as input to the perl script? Don't know if it's workable.

推荐答案

如果XML不复杂,则可以编写一个简单的脚本将其转换为其他格式.例如简单的哈希,请使用Data :: Dumper将其转储到文件中,并在AIX上评估输出.

If the XML is not complex, you can write a simple script that convert it to other format. such as simple hash, use Data::Dumper to dump it to a file, and eval the output on your AIX.

如果很复杂,则需要在XML中进行自己的内存表示(注意属性,子元素,文本节点,名称空间...您的输入有多复杂?),然后转储/评估.

If it is complex, you need to make your own in-memory representation of the XML, (with noting attributes, child elements, text nodes, namespaces... how complex is your input?) and dump / eval that.

要逃避的示例代码:(未经测试)

sample code to evaling: (untested)

# read the data to variable
open my $fh, "<", "dumpfile.txt" or die "file not found";
my $dump = do { local $/ = <$fh> };
close $fh;
# eval the dump
my $VAR1;
eval $dump;

这篇关于如何在不导入xml解析器模块的情况下将xml数据传递到perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆