SPUG: Ordered Hash Tie Class
iee2 at site42.com
Tue Apr 6 13:48:35 CDT 2004
On Tue, 2004-04-06 at 10:34, Chris Wilkes wrote:
> On Tue, Apr 06, 2004 at 10:03:13AM -0700, Ingmar Ellenberger wrote:
> > I need it to be able to handle multiple values for a given key and have
> > handlers to deal with them.
> > What I'm REALLY trying to do is create tools to manipulate Java property
> > files while while maintaining comments and whitespace.
> Can you have multiple values for a single key in java property files?
Sort of, but not really. I'm no Java expert, but I believe it works
this way. Java treats these properties as constants, so it takes the
first instance of a property and ignores all others. That makes the
order you load properties files rather important. I find the whole
thing a little backward - must have been designed be committee.
I was planning to parse out all comments into a single '_comment' key in
the hash 'cause I really don't care about the (contents of the)
comments. I just want to make sure that as I add values and merge
files, the comments would also go with it so that the Java developers
wouldn't get all confused.
> Most of mine look like this:
> # this is a comment
> # remote directory
> # username for scp
> as for whitespace, I haven't seen that in use either, ...
When saying whitespace, I meant blank lines in addition to comments. I
would presume that whitespace in properties would be preserved.
> I take it eventually you want to get to something like this:
> $prop = My::JavaProperty->new("clothingreport.properties");
> @keys = $prop->getKeys();
> $columns = $prop->get("columns");
> $prop->set("columns", $columns);
That's pretty much it. Also wanted to be able to merge multiple
property files as well.
> What I would do is slurp everything into an array (as property files are
> never that long) and then when someone requests a key, just go through
> the array looking for it, keeping track of its position in the array.
> Then when they change it, just change that position's value.
That was my original thought, but I was aiming to be a little more
> And I could of saved myself a lot of time by looking on CPAN first, as
> there's a Config::Properties module out there:
> so I would see if that suits your needs.
Took a quick look at it, and from reading the code, it seems to ignore
all comments (i.e. doesn't preserve them). I could be missing something
though. The code isn't as clearly written as it could be.
More information about the spug-list