我应该使用 YAML 还是 JSON 来存储我的 Perl 数据? [英] Should I use YAML or JSON to store my Perl data?

查看:14
本文介绍了我应该使用 YAML 还是 JSON 来存储我的 Perl 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去 6 个月左右的时间里,我一直在使用 YAML 格式并取得了相当大的成功.

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

然而,YAML 解析器的纯 Perl 实现相当烦躁地手写一个可读的文件并且有(在我看来)烦人的怪癖,例如在文件末尾需要换行符.这也是与我的程序的其余部分相比,速度非常慢.

However, the pure Perl implementation of the YAML parser is fairly fidgety to hand-write a readable file for and has (in my opinion) annoying quirks such as requiring a newline at end of the file. It's also gigantically slow compared to the rest of my program.

我正在考虑我的项目的下一步发展,我正在考虑改用 JSON(实际上是 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?

今天看来,这对于简单来说是更好的长期格式Perl、YAML 或 JSON 中的数据描述,为什么?

Which appears today to be the better long-term format for simple data description in Perl, YAML or JSON, and why?

推荐答案

YAML 与 JSON 在 Perl 中还没有解决,我承认我倾向于在这中间.我的建议是,两者都会让你获得尽可能多的社区牵引力.我会根据格式的各种利弊做出决定.我分解了各种数据序列化选项,如下所示(我将访问社区 wiki,以便人们可以添加):

YAML vs JSON is something very much not settled in Perl, and I will admit I tend to be in the middle of that. I would advice that either is going to get you about as much community traction. I'd make the decision based on the various pros and cons of the formats. I break down the various data serializing options like so (I'm going to community wiki this so people can add to it):

YAML 专家

  • 人性化,人们在不知不觉中编写基本的 YAML
  • 所见即所得字符串
  • 富有表现力(具有 TMTOWDI 特性)
  • 可扩展类型/元数据系统
  • Perl 兼容的数据类型
  • 便携
  • 熟悉(很多内联和字符串语法看起来像 Perl 代码)
  • 如果您有编译器 (YAML::XS),则可以很好地实现
  • 良好的 Perl 数据转储能力
  • 紧凑地使用屏幕空间(可能,您可以格式化以适应一行)

YAML 缺点

  • 大规格
  • 不可靠/不完整的纯 Perl 实现
  • 空格作为语法可能会引起争议.

JSON 专家

  • 人类可读/可写
  • 小规格
  • 良好的实现
  • 便携
  • Perlish 语法
  • YAML 1.2 是 JSON 的超集
  • 紧凑使用屏幕空间
  • Perl 友好的数据类型
  • 很多东西都处理 JSON

JSON 缺点

  • 字符串不是所见即所得的
  • 不可扩展性
  • 某些 Perl 结构必须以特定方式表示(对象和全局对象)
  • 缺乏表达性

XML 专家

  • 广泛使用
  • Web 开发人员熟悉的语法
  • 优质 XML 模块的大型语料库
  • 架构
  • 搜索和转换数据的技术
  • 便携

XML 缺点

  • 人类阅读和写作很乏味
  • Perl 以外的数据结构
  • 缺乏表达性
  • 大规格
  • 冗长

Perl/Data::Dumper Pros

  • 无依赖关系
  • 令人惊讶的紧凑(带有正确的标志)
  • 对 Perl 友好
  • 几乎可以转储任何东西(通过 DDS)
  • 富有表现力
  • 紧凑使用屏幕空间
  • 所见即所得字符串
  • 熟悉

Perl/Data::Dumper 缺点

  • 不可移植(其他语言)
  • 不安全(没有英勇的措施)
  • 非 Perl 程序员难以理解

可存储的优点

  • 紧凑?(没有数字支持)
  • 快吗?(没有数字支持)

可存储的缺点

  • 人类敌对
  • 跨存储版本不兼容
  • 不可移植(其他语言)

这篇关于我应该使用 YAML 还是 JSON 来存储我的 Perl 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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