Date: Thu, 16 Jan 2003 21:44:59 -0800 From: "Crist J. Clark" <crist.clark@attbi.com> To: freebsd-chat@freebsd.org Subject: Script Challenge Message-ID: <20030117054458.GA50247@blossom.cjclark.org>
next in thread | raw e-mail | index | archive | help
I ran into a little problem today and needed to write a quick script. The problem isn't to tough, and I got it done with a 15 line-or-so Perl script, but there must be a more elegant way to do this. Here's the basic problem: I have a flat file that contains a database. Items in the database can contain sub-items which in turn contain sub-items with no hard limit to the recursion. The format of the file is, :b_item (value) :a_item ( :z_subitem(value) :x_subitem(value) :y_subitem( :r_subsubitem(value) :t_subsubitem(vaule) :s_subsubitem(value) ) :w_subitem(value) ) :c_item(value) That is, "values" whether individual items or lists, are surrounded by parentheses. (You need not worry about parentheses in "values" or the closing parentheses of a list not showing up on its own line, it always does.) I want to sort each level. That is, the above would become, :a_item ( :w_subitem(value) :x_subitem(value) :y_subitem( :r_subsubitem(value) :s_subsubitem(value) :t_subsubitem(vaule) ) :z_subitem(value) ) :b_item (value) :c_item(value) Like I said, I used a Perl script with a recursive function to do it, but it ain't all that pretty. I suspect I'm missing a really cool way to do it. Any suggestions? (Any language will do.) -- Crist J. Clark | cjclark@alum.mit.edu | cjclark@jhu.edu http://people.freebsd.org/~cjc/ | cjc@freebsd.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030117054458.GA50247>