I don't get many chances to use Ruby, but when I do I remain breathlessly impressed with it. Tonight, I had to write a program to extract the XML meta-data from a mass collection of documents (The Journal Entries, naturally) and process that meta-data into fields, which would then get output as a CSV so I could edit it with a spreadsheet. One of the tricky parts was putting the filename, which is not part of the embedded metadata, as the first column in the CSV.
I did it in one line. Not a Perl line where, a month from now, I'll have no idea what the heck I was writing. One readable, understandable, clear and concise line.
Oh, I so like this language. I wish I had more opportunities to use it.
I did it in one line. Not a Perl line where, a month from now, I'll have no idea what the heck I was writing. One readable, understandable, clear and concise line.
Oh, I so like this language. I wish I had more opportunities to use it.
no subject
Date: 2006-09-01 07:48 am (UTC)Thanks so much, Elf, now I have another language to learn....
no subject
Date: 2006-09-01 11:54 am (UTC)no subject
Date: 2006-09-01 01:15 pm (UTC)["title", "arc", "pubdate", "wordcount", "cookie", "wikipage", "storycode"].collect {|c|
XPath.first(Document.new(File.open('temp/' + f, "r")), '//' + c).text || "n/a"}.unshift(f).join("\t")
}.join("\n")
Looking at it twice, maybe it's not so readable in the morning. But I can start to puzzle out the intention and arrive at understanding much quicker than I could with Perl.