Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Problem using YAML

by perlfan (Curate)
on Dec 29, 2011 at 20:58 UTC ( #945557=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Problem using YAML
in thread Problem using YAML

Because YAML has a particular format, delineated with the "---", you will have to add a top level key that contains the contents you desire. When You decode, you will have to deference the hash key that this corresponds to. For example:

--- This: top level mapping is: - a - YAML - document
will decode to a hash that looks like:
my $yaml_hash_ref = { This => 'top level mapping', is => ['a', 'yaml', 'document'] };
Therefore, if you want "%This" to be your hash variable, you need to do this:
my %This = %{$yaml_hash_ref->{This}};
If you want the whole structure, you just use whatever YAML::decode gives you, i.e., YAML's encode doesn't take into account the name of your variable containing the data structure to convert to YAML. Similarly, decode returns a data structure reference (scalar, array, or hash) depending on how complex (e.g., hash references contain all non-trivial data structures implied by the YAML).


Comment on Re^3: Problem using YAML
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-08-31 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls