Perl 中的结构化模板
我一直在 perl 中开发 nmap 解析器,我一直使用它,但是我想以非常结构化的方式写入文件。有问题的文件将是 nagios ports.cfg(我会在他们的 wiki 上使用 nmap2nagios.pl,但它似乎不起作用,而且我自己编写自己的文件很有趣)。
文件条目应如下所示
define hosts {
host_name $host_name || $host_ip
alias $os
address $host_ip
}
上面只是一个示例,但我希望您能明白。任何帮助将不胜感激!我四处寻找一些模板模块,但它们似乎都非常适合 cgi。
I've been working on an nmap parser in perl, I've been going well with it, however I would like to write to a write to a file in a very structured manner. The file in question would be a nagios hosts.cfg (I'd use the nmap2nagios.pl on their wiki but it doesn't seem to be working and i'm having too much fun writing my own).
The file entries should look like this
define hosts {
host_name $host_name || $host_ip
alias $os
address $host_ip
}
The above is just an example but I hope you get the idea. Any help will be appreciated! I've looked around for some template modules but they all seemed to be very geared towards cgi's.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我赞同尼克的建议。一些灵感:
注意:模板引用模板工具包
I second Nick's suggestion. Some inspiration:
Note: The Template refers to Template Toolkit
我总是使用 Template Toolkit 来输出任何结构化文档。它并不是专门针对 CGI - 例如,我很高兴地使用它来编写配置文件。
I would always use Template Toolkit for outputting any structured document. It's not specifically geared to CGI - I've used it happily to write config files for example.
也许您正在寻找格式。我从未使用过它,语法看起来很疯狂,但你不需要任何模块。
Maybe you are looking for formats. I never used it and the syntax looks insane but you don't need any modules.