![[User Picture]](http://l-userpic.livejournal.com/265901/210712) | From: gaal 2006-05-07 04:37 am (UTC)
| (Link)
|
You're missing a /i modifier in these regexps. But maybe use YAML instead of doing your own parsing? That Apache conf format always looked a little weird to me.
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 04:54 am (UTC)
| (Link)
|
YAML's for YAML nerds only. It used to be cool but now it's overbloated and overcomplex and even regular programers hate it, not to mention users/sysadmins.
Also, sysadmins know the Apache format. Therefore, it wins.
Q.E.D.
![[User Picture]](http://l-userpic.livejournal.com/265901/210712) | From: gaal 2006-05-07 05:13 am (UTC)
| (Link)
|
Hey, whatever works.
When was it not bloated, in your opinion?
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 05:38 am (UTC)
| (Link)
|
When I first learned YAML (pre-Python/Ruby committee standardization as I'm told?) it was dictionaries and lists, and you could fit the entire syntax (and parser) in your head. Now look at it: http://yaml.org/spec/current.htmlLook how tiny your vertical scroll handle gets! Read some of those examples! OMFGZ. I'd rather use JSON, but no sysadmins know that either.
![[User Picture]](http://l-userpic.livejournal.com/9624370/1571) | From: evan 2006-05-07 06:29 am (UTC)
| (Link)
|
I actually was about to write the same comment to Brad ("why not YAML?") and then I saw his response and realized that is my response as well. I guess it could be hidden by a library, but yeah: every time I've wanted to use YAML I've sat down, tried to start reading about how it works, and decided it was way too complicated for what I needed.
FWIW, I think the Apache format is kinda lame too: why use angle brackets if you're not gonna be XML? Same thing (nesting) could be accomplished with curlies and it's less typing.
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 12:21 pm (UTC)
| (Link)
|
Familiarity to sysadmins.
How much do /I/ hate it when I go to configure some program and the config file is in Python (say, Xen, or GNU Mailman) and I know language $Foo better. Apache-style is common ground that everybody has warm fuzzies about.
't' and 'f', but no 'y' or 'n'?
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 04:55 am (UTC)
| (Link)
|
Committed revision 201.
![[User Picture]](http://l-userpic.livejournal.com/31895888/2346955) | From: ckd 2006-05-07 05:05 am (UTC)
| (Link)
|
Yeah. Also, I'd probably rewrite those regexps a bit:
/^1|y(es)?|t(rue)?|on|enabled?$/i; /^0|n(o)?|f(alse)?|off|disabled?$/i;
(Yes, I realize that "n(o)?" doesn't need the paren grouping. Take it out if it offends you. Readability beats efficiency for something that isn't getting run in a tight loop.)
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 05:08 am (UTC)
| (Link)
|
Readability is subjective. :-)
![[User Picture]](http://l-userpic.livejournal.com/31895942/2346955) | From: ckd 2006-05-07 05:37 am (UTC)
| (Link)
|
Says the guy who's writing this in Perl. (It could be worse; it could be APL. Or sendmail.cf.)
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 05:40 am (UTC)
| (Link)
|
I've sure you've heard it, but: "You can write clean and ugly code in any language." I'm not going to say my Perl is the most beautiful it could be, but it's pretty sexy.... a lot more than what people think of when they hear Perl, which is often sysadmin-Perl. (although I'd argue that syadmins prefer sysadmin perl to my Perl....)
This thread goes nowhere productive. :-)
Perl in my pants is reproductive not a good idea.
Um, and it was for readability that you dumped a lot of punctuation in there instead of having separate slots for each item?
Yeah, well. You're still right.
I guess I'm kinda surprised there isn't a "parse Apache config files" Perl module on CPAN already.
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 06:02 am (UTC)
| (Link)
|
There are several.
We looked into it but it didn't pay off for the extremely limited subset we needed. If we need more later, we could go that route. But as is, it's almost no code, and 7/8ths of it is integration with DJabberd, not parsing.
I think I'd say "booleanity" before I said "booleanness"...
![[User Picture]](http://l-userpic.livejournal.com/265901/210712) | From: gaal 2006-05-07 03:28 pm (UTC)
| (Link)
|
ObPerl6 :via
That function was fun because it was in declarative, guardy style. In Haskell, where pattern matching means something else than it does in Perl, you have that in sweet, sweet syntax. In Perl 6, the syntax is less sweet in the general case (more punctuation), but here because of the regular expression it's quite nice:
multi sub as_bool (Str $val where rx:i/^ 1 | yes | etc/) { 1 } multi sub as_bool (Str $val where rx:i/^0 | no | etc/) { 0 } multi sub as_bool (Str $val) { !!! }
The last variant is actually optional: you'll get an error anywhere when multidispatch fails, and it should contain the argument.
![[User Picture]](http://l-userpic.livejournal.com/54541970/2) | From: brad 2006-05-07 11:49 pm (UTC)
| (Link)
|
So cool. |