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

查看:130
本文介绍了我应该使用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数据的能力
  • 紧凑地使用屏幕空间(可能,您可以格式化以适合一行)
  • Human friendly, people write basic YAML without even knowing it
  • WYSIWYG strings
  • Expressive (it has the TMTOWDI nature)
  • Expandable type/metadata system
  • Perl compatible data types
  • Portable
  • Familiar (a lot of the inline and string syntax looks like Perl code)
  • Good implementations if you have a compiler (YAML::XS)
  • Good ability to dump Perl data
  • Compact use of screen space (possible, you can format to fit in one line)

YAML缺点

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

JSON专家

  • 人类可读/可写
  • 小规格
  • 良好的实现方式
  • 便携式
  • 完成语法
  • YAML 1.2是JSON的超集
  • 紧凑地使用屏幕空间
  • Perl友好的数据类型
  • 很多东西都可以处理JSON
  • Human readable/writable
  • Small spec
  • Good implementations
  • Portable
  • Perlish syntax
  • YAML 1.2 is a superset of JSON
  • Compact use of screen space
  • Perl friendly data types
  • Lots of things handle JSON

JSON缺点

  • 字符串不是所见即所得
  • 没有扩展性
  • 某些Perl结构必须临时表达(对象和glob)
  • 缺乏表达力

XML专家

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

XML缺点

  • 乏味的人类阅读和写作
  • Perl以外的数据结构
  • 缺乏表达力
  • 大规格
  • 详细

Perl/Data :: Dumper Pros

  • 没有依赖项
  • 令人惊讶的紧凑(带有正确的标志)
  • Perl友好
  • 可以转储几乎所有内容(通过 DDS )
  • 富有表现力
  • 紧凑地使用屏幕空间
  • 所见即所得字符串
  • 熟悉
  • No dependencies
  • Surprisingly compact (with the right flags)
  • Perl friendly
  • Can dump pretty much anything (via DDS)
  • Expressive
  • Compact use of screen space
  • WYSIWYG strings
  • Familiar

Perl/Data :: Dumper Cons

  • 非便携式(其他语言)
  • 不安全(不采取英勇措施)
  • 非Perl程序员不可理解的

可存储的专业人士

  • 紧凑? (没有数字可备份)
  • 快? (没有数字可备份)

可存储的缺点

  • 人类敌对
  • 在所有可存储版本之间不兼容
  • 非便携式(其他语言)

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

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