Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Problems? Is your data what you think it is?
 
PerlMonks  

Re: YAML for logs?

by mattr (Curate)
on Nov 26, 2006 at 07:38 UTC ( #586079=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: YAML for logs?
Download Code
Re^2: YAML for logs?
by blazar (Canon) on Nov 26, 2006 at 10:05 UTC
    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.

    Well, whatever: I wouldn't be doing this from the command line anyway.

    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.

    But the point is that "--- \n" wouldn't be a separator. It would rather be a sort of introductory line. The concept is close, but not quite the same. Which is why I wrote that I'd have to massage the chunks anyway. Perhaps, also in view of something like that hinted elsewhere, a multiline per record format based on a data serialization one "should" (from my blazarcentric POV) be paragraph oriented...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-04-20 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls