|The stupid question is the question not asked|
An Idiot's Guide to YAMLby scorpio17 (Abbot)
|on Jun 08, 2007 at 20:01 UTC||Need Help??|
I recently discovered YAML and thought it was very cool, so I've been anxiously awaiting a chance to actually use it. Well, I just started a new project and I thought YAML would be perfect for loading the config file.
I immediately had problems, because the YAML parser was unable to read in my config file. It gave me an error saying 'stream does not end with newline' - which left me perplexed because the file did, indeed, have a newline!
Since the problem seemed to be with the YAML syntax, I thought it would be clever to make Perl generate the file for me. I hardcoded a data structure in Perl and wrote out YAML using the Dump() command:
I saved the output as config.yml, which looks like this:
This looked pretty much like what I already had, and sure enough, when I tried reading it back in, I again got the same error as before. This is what my reader script looked like:
I am too ashamed to admit on this board how long it took me to figure out the problem here, but I DID read the docs on cpan, search on google, search here, and search on the official yaml site, to no avail.
Here's the solution - which I'm posting here on the off chance that someone, some where, some day, may have the same bad fortune that I did, and will find this helpful.
And there you have it: the Load function does not load a FILE, it loads a STREAM. Okay - so now I feel like an idiot. But I went back and read the documentation again, and this really is not that obvious. An example would have helped a bunch. There wasn't one there, but now there's one here.
After going back and very carefully reading the docs a third time (after bossman's replay) I finally found what I was really looking for all along - the LoadFile function:
'You're Welcome' in advance...