in reply to complex string matching

The way I see it, you don't have a complex string-matching problem. The configuration file is effectively (key,value) pairs with syntatic sugar wrapped around them to make them into valid javascript. What you have is a hash-lookup problem.

The way I would approach it is to read in your new configuration (key,value) pairs from wherever and put it in a hash. Then you read in your user config file, a line at a time, pulling out the key and value from the line. Update the hash following whatever rules you want for collisions. Finish by writing your hash as the new user config with its javascript wrapping.

SMOP. I leave the coding as an exercise for the reader. :-)

Replies are listed 'Best First'.
Re^2: complex string matching
by thargas (Deacon) on Nov 04, 2010 at 13:14 UTC

    Oh yes. About making this work for other types of files: I wouldn't bother until I had a second type to compare. However, it would still be straightforward. Your munging class would have parse() and write methods which would be overridden for each type.

    It'd be a bit more difficult if the files could contain more than one kind of line, but the solution I'd use would simply go from a (key,value) pair to a (type, key, value) triple and add another layer to the hash.