http://www.perlmonks.org?node_id=461980


in reply to Re^2: YAML newbie help
in thread YAML newbie help

Indeed, answering my own question after reading more of the long, but well-written specification: a more concise, but equivalent version, is of course:
- date: 2005-06-01 team: [ Jack, Jill, Joe ] boss: Clara - date: 2005-06-02 team: [ Harry, Hillary, Howie ] boss: Victoria
Even more concise, each day can be made to fit on one line:
- { date: 2005-06-01, team: [ Harry, Hillary, Howie ], boss: Clara + } - { date: 2005-06-02, team: [ Jack, Jill, Joe ], boss: Victor +ia }
which makes it more readable as a table.

I wonder if you can simplify even further, by factoring out the hash keys? Something on the order of:

# INCORRECT YAML SYNTAX - { date:, team:, boss: } - { 2005-06-01, [ Harry, Hillary, Howie ], Clara } - { 2005-06-02, [ Jack, Jill, Joe ], Victoria }
Probably not.

Replies are listed 'Best First'.
Re^4: YAML newbie help
by PodMaster (Abbot) on May 31, 2005 at 10:42 UTC
    I see. I always start with `perldoc YAML', so I would've approached the problem the same way grinder would, akin to
    use YAML; my( @foo ) = ({ 'date' => '2005-06-01', 'boss' => 'Clara', 'team' => [ 'Jack', 'Jill', 'Joe' ] }, { 'date' => '2005-06-02', 'boss' => 'Victoria', 'team' => [ 'Harry', 'Hillary', 'Howie' ] } ); local $YAML::Indent = 4; local $YAML::UseFold = 1; print Dump( \@foo ); __END__ --- - boss: Clara date: 2005-06-01 team: - Jack - Jill - Joe - boss: Victoria date: 2005-06-02 team: - Harry - Hillary - Howie
    Too bad there isn't an option yet to compress sequences.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      > I always start with `perldoc YAML'

      That's what I did too, but the synopsis actually starts with YAML, not with Perl structures.

      grinder and your technique is great for those who are good at thinking in, and writing, Perl data structures. I must shamefully confess that, despite long experience programming Perl, I have trouble distinguishing braces from brackets from curlies, and remembering which does what. So I thought to myself: "Hey, YAML, human-readable! Maybe it can save me from wearing out my AltGr key! (on French keyboard)". But YAML turned out not to be as DWIM as I expected, which isn't surprising. Hence the need for lots of examples for lazy newbies like me.

      Maybe as penance (and when I have time, this was all supposed to be a timesaver...) I'll write up a translation of perldsc into YAML.

        Excellent idea, go for it! I don't recall seeing Manual Guilt work so well before :D Just scan for Declaration of and YAML::Dump() it, shouldn't take long at all

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.