I've been using the YAML format with reasonable success in the last 6 months or so.

但是,YAML解析器的纯Perl实现相当 为和手写可读文件很烦躁(在我看来) 令人讨厌的怪癖,比如要求在文件末尾换行.它也是 跟我节目的睡觉相比慢得惊人.

I'm pondering the next evolution of my project, and I'm considering using JSON instead (a mostly strict subset of YAML, as it turns out). But which format has the most community traction and effort in Perl?

今天看来,这是SIMPLE的更好的长期格式 用Perl、YAML或JSON描述数据,为什么?

推荐答案

YAML VS JSON在Perl是很难解决的问题,我承认我倾向于这一点.我的建议是,这两种方法都能让你获得同样多的社区吸引力.我会根据各种格式的利弊做出决定.我对各种数据序列化选项进行了分解,比如(我将访问社区wiki,这样人们就可以添加到其中):

YAML Pros

  • 对人类友好,人们在不知情的情况下编写基本的YAML
  • WYSIWYG strings
  • 有表现力的 (it has the TMTOWDI nature)
  • Expandable type/metadata system
  • Perl兼容的数据类型
  • 便携
  • 熟悉的 (a lot of the inline and string syntax looks like Perl code)
  • 如果您有编译器(YAML::XS),就会有好的实现
  • 良好的Perl数据转储能力
  • 屏幕空间的紧凑使用 (possible, you can format to fit in one line)

YAML Cons

  • 大规格
  • 不可靠/不完整的纯Perl实现
  • Whitespace as syntax can be contentious.

JSON Pros

  • Human readable/writable
  • 小规格
  • Good implementations
  • 便携
  • 英语语法
  • YAML 1.2 is a superset of JSON
  • 屏幕空间的紧凑使用
  • Perl friendly data types
  • 很多事情都可以处理JSON

JSON Cons

  • Strings are not WYSIWYG
  • No expandability
  • Some Perl structures have to be expressed ad-hoc (objects & globs)
  • Lack of expressibility

XML Pros

  • 广泛使用
  • web开发人员熟悉的语法
  • 大量优秀的XML模块语料库
  • Schemas
  • 搜索和转换数据的技术
  • 便携

XML Cons

  • 对人类来说,读和写是乏味的
  • Data structures foreign to Perl
  • Lack of expressibility
  • 大规格
  • Verbose

Perl/Data::Dumper Pros

  • 没有依赖关系
  • 令人惊讶的紧凑(使用正确的旗帜)
  • Perl friendly
  • Can dump pretty much anything (via DDS)
  • 有表现力的
  • 屏幕空间的紧凑使用
  • WYSIWYG strings
  • 熟悉的

Perl/Data::Dumper Cons

  • 不可移植(到其他语言)
  • 不安全(没有英勇的措施)
  • Inscrutable to non-Perl programmers

Storable Pros

  • Compact? (don't have numbers to back it up)
  • Fast? (don't have numbers to back it up)

Storable Cons

  • Human hostile
  • 可存储版本之间不兼容
  • 不可移植(到其他语言)

Json相关问答推荐

中间初始化的Jolt配置

合并二维数组的Jolt表达式

如何使用Aeson解码带有Unicode字符的JSON文件?

Pandas 对REST API的自定义响应

在Zig中解析JSON失败

组合不同属性的Jolt Spec

如何避免解析 ISuperObject 类型字段中的 json 对象

当并非所有子对象都有 Select 器字段时 Select

Groovy JsonBuilder 在for循环中添加数组元素

每次在 SoapUI 中发送请求时,将 JSON 响应的子 node 分配给项目变量

将 colly 包输出文本添加到 golang 中的映射

如何在 Django 的模板语言中获取 json 键和值?

缺少所需的请求正文内容:org.springframework.web.method.HandlerMethod$HandlerMethodParameter

错误字符串的长度超过了maxJsonLength属性设置的值

应该使用什么标头将 GZIP 压缩 JSON 从 Android 客户端发送到服务器?

有没有办法使用 Jackson 将 Map 转换为 JSON 表示而不写入文件?

带有方法参数的 WCF webHttpBinding 错误. 最多可以在没有包装元素的情况下序列化一个主体参数

as_json 没有在关联上调用 as_json

杰克逊在通用列表中读取 json

Jersey 2.0 相当于 POJOMappingFeature