|go ahead... be a heretic|
Unwrapping values in a templateby hacker (Priest)
|on Nov 14, 2003 at 13:44 UTC||Need Help??|
hacker has asked for the
wisdom of the Perl Monks concerning the following question:
I have a hand-rolled template of key=value pairs that I'm parsing out of the body of an email, and checking each value for validity. One of these keys takes a URL as a value. Many mail readers will wrap long urls to the next line, so my original template, which looks like this...
...will end up looking like this, after I receive it in an email:
What I'm trying to do, is "unwrap" that wrapped field before I process the template with Config::General to parse out the keys. Once the keys are properly unwrapped, Config::General has no problem with it. I also looked into Config::General's '-SplitDelimiter' option, but it doesn't consider a newline as whitespace, and my attempts at defining a proper delimeter there failed.
I've been working with a few monks on the CB (thanks diotalevi) to try to work this out, and we've come up with two possibilities, each with a flaw of their own. The problem is that some keys can be left blank, with no value, while others can have values.
This code below, one example of the unwrap code, which properly treats blank keys as it should, but doesn't unwrap the 'home_url' field back up to the previous line:
This next bit of code actually unpwraps the 'home_url' field properly, but also unwraps keys with blank values into the value field of the previous key:
This results in the output that looks like this:
Note how the 'home_url' key wraps up into the value side of the previous key.
What I'm trying to do, is keep all keys intact, including the 'home_url' one (which is the only key long enough to wrap, the others don't wrap).
Any helpful pointers here?
Update: I think jeffa is the winner on this one, the working code is now as follows: