Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: YAML newbie help

by grinder (Bishop)
on May 31, 2005 at 09:46 UTC ( [id://461972]=note: print w/replies, xml ) Need Help??


in reply to YAML newbie help

I'm looking for some documentation that can get me started real quick, with cut-and-pasteable practical examples.

I've always found that the easiest way to write code to emit valid YAML is to create the target structure in Perl and dump it out, and look at the result.

#! /usr/local/bin/perl -w use strict; use YAML; my $r = [ 1, 2, { a => [2, 3], b => [4, 5, 6] }, { c => { d => 'd', e => 'e', f => [6, 7, 8] }, d => [10, 20, 3 +0] }, ]; print YAML::Dump($r), "\n";

Which produces

--- - 1 - 2 - a: - 2 - 3 b: - 4 - 5 - 6 - c: d: d e: e f: - 6 - 7 - 8 d: - 10 - 20 - 30
And from there it's pretty easy to whip up some code that produces this target output. From these sorts of empirical observations you can usually figure out what YAML you need to write to achieve the data structure you want to play with.

- another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://461972]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found