From owner-freebsd-chat Thu Jan 16 21:45: 4 2003 Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C2F4E37B401 for ; Thu, 16 Jan 2003 21:45:02 -0800 (PST) Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by mx1.FreeBSD.org (Postfix) with ESMTP id 424C043F6D for ; Thu, 16 Jan 2003 21:45:02 -0800 (PST) (envelope-from crist.clark@attbi.com) Received: from blossom.cjclark.org (12-234-89-252.client.attbi.com[12.234.89.252]) by rwcrmhc52.attbi.com (rwcrmhc52) with ESMTP id <20030117054501052008uld5e>; Fri, 17 Jan 2003 05:45:01 +0000 Received: from blossom.cjclark.org (localhost. [127.0.0.1]) by blossom.cjclark.org (8.12.6/8.12.3) with ESMTP id h0H5j0eq050497 for ; Thu, 16 Jan 2003 21:45:00 -0800 (PST) (envelope-from crist.clark@attbi.com) Received: (from cjc@localhost) by blossom.cjclark.org (8.12.6/8.12.6/Submit) id h0H5ixj1050493 for freebsd-chat@freebsd.org; Thu, 16 Jan 2003 21:44:59 -0800 (PST) X-Authentication-Warning: blossom.cjclark.org: cjc set sender to crist.clark@attbi.com using -f Date: Thu, 16 Jan 2003 21:44:59 -0800 From: "Crist J. Clark" To: freebsd-chat@freebsd.org Subject: Script Challenge Message-ID: <20030117054458.GA50247@blossom.cjclark.org> Reply-To: "Crist J. Clark" Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-URL: http://people.freebsd.org/~cjc/ Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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