It seems that the problem he had was not with the YAML config, but with reading the documentation. However, in answer to your question about why I would bother to use YAML, let me give you an example.

In my current project, I have a large amount of config, stored in a directory tree containing 59 separate YAML files, for ease of management.

I loaded and merged (with Config::Loader) all of this data, and then printed it out to two separate files, one with YAML::Syck and one with Data::Dumper. Both were set to use two spaces as an indent.

YAML Perl Perl > YAML ------------------------------------ Lines 3279 4150 27% Size 85 kB 139 kB 63% Size (no spaces) 49 kB 66 kB 35%
While some would argue that the last measure is irrelevant, because YAML requires white space, I would say that it IS relevant because, to be legible and maintainable, Perl also needs white space. Instead those numbers are a measure of the extra punctuation that is needed to represent your data - the more punctuation, the less visible is the stuff that actually matters.

In practice, I've added a lot of extra white space and comment lines etc, so that my actual config is 3350 lines and 105kB - still a good deal smaller than a compact Perl version. And the extra stuff is either unobtrusive (whitespace) or obviously not part of the actual data (comments). I would assume a similar growth in size if I were to do the same thing in Perl.

People complain about how difficult it is to edit YAML by hand, a sentiment I do not understand at all. The format is simple and easy to read. This example covers 95% of my configuration needs:

scalar: value array: - element 1 - element 2 - element 3 hash: key1: value1 key2: value2 key3: value3

There is a lot more you can do with it, such as referencing other data structures within the YAML, recursion, loading Perl code, here docs and multiline scalars. However, most of this is unnecessary for day to day usage.

The one thing that seem to trip people up is the whitespace. YAML doesn't accept tabs as whitespace and, in my opinion, this is a good thing. How wide is a tab? PBP recommends using spaces for indenting Perl code instead of tabs for this very reason. And quite frankly, if your Perl indentation is a mess, it's going to be difficult to maintain anyway. Clear indentation makes for legibility. Any editor that uses spaces for tabs and can do block indents will handle YAML with ease.

Opinions about YAML are strongly polarised, and I'm not suggesting that it is the One True Way. But there are a lot of nay-sayers that give YAML a bad reputation, and I think it is undeserved. It is a very flexible, easy, useful and widely available format, and in my opinion, deserves its place at the table.

Clint


In reply to Re^2: An Idiot's Guide to YAML by clinton
in thread An Idiot's Guide to YAML by scorpio17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.