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


in reply to YAML for logs?

I have only used YAML a little as yet but am going to be using it a lot more because of Catalyst and also for non-Catalyst work e.g. for object template configuration or whatever. For simple things I use either Config::IniFiles or more often just a simple tab-separated text file with hash keys (for error messages) though these might all end up in YAML soon.

I thought about setting the input record separator (see perlvar, perlrun) to "---\n" which can be done, but on the command line perl only seems able to set a single character separator with the command line switches. Then I looked at File::Tail. You might like to contact the author is thinking of adding record separator support if you have a good reason for it, and this seems like a good one (or do it yourself and submit back to him later).

Well I fiddled with the command line and got this far: cat test.yml|perl -nla -0777 -F/---/ -e 'foreach $s (@F) {print "***STREAM***$s\n";}'|more but it doesn't work with tail as far as I can see.

So if you want to follow a file, I'd guess either build on File::Tail, or better yet roll your own by reading from a pipe within a perl program. In the past I've used an interactive shell based on Term::Readline to try out multiline scripts with the Gimp, and it worked great. Come to think of it what about ysh? ... and lo and behold I open /usr/bin/ysh and it is using Term::Readline. I would guess the easiest thing to do would be to just modify ysh. I got cat to work with it but not tail, not sure why. Also for some reason it gave a parse error (bad alias) for the long data structure posted in the thread.

Oh, one more datapoint. Boulder is something like yaml made for bioperl, and used in piped workflows. So you aren't the first person to want to do this and it shouldn't be too hard. If I was doing this I would probably just roll my own program I think to watch a file and pull in lines, decoding from yaml when a separator is reached. Term::Readline might do it too. Bioperl does something like what you want and it might even work on yaml files as-is. It's used to slurp in long gene text files.