regex instead of a new lover. . .
am 25.11.2007 08:47:11 von ben.rogersWell, I'd rather get ahold of anusha and forget this whole business,
but I guess I should finish this first:
I have a config file that get read by my main script. A sub parses the
file and does just fine under simple circumstances. It finds all
this:
Index directory === C:/
HTML resource directory === C:/Aardvark/res/user_html/test_index
HTML resources === *.html *.htm
File types to index === html|htm|pdf|xml|zip|mif|txt
# Frame template options:
Template directory === C:/Aardvark/res/frame_templates
Template types === *.fm
Template objects === Para,Char,XRefs,Vars,Tables,Page Layouts,Math
Defs,Ref Pages,Conditions
I get the values on both sides of the ===.
The problem is that when there is a . or ? (and maybe other things)
it fails:
# Stuff I can't read
Title rule choices === title.fm
TOC rule choices === TOC.fm
Appendix rule choices === apx.fm
Index rule choices === IOM.fm|IX.fm
Body rule choices === Everything else!
Other rule choices 1 === ????????
Other rule choices 2 === ????????
What I am looking for is a regex that finds anything one line at a
time separated by ===. In other words, all my config options are on a
single line like: key === value.
I started guessing, then started researching, and now I ask the
experts: what will work?
Stuff I tried:
while(<$fh>){
if (/#########/){
last;
} # todo: make this match . and ?
elsif (/^\ *(.*?)\ *===\ *(.*?)\ *$/){ # original
# elsif (/^\ *(.*?)\ *===\ *(.*?)\ *$/sm){
# elsif (/\A\ *(.*?)\ *===\ *(.*?)\ *\Z/sm){
# elsif (/^ *(.*?) *=== *(.*?) *$/){
# elsif (/^ *(.*?) *=== *(.*?) *$/sm){
# elsif (/^\ *(.*?)\ *===\ *(.*?)$/is){
# elsif (/^(.*?)===(.*?)$/){
# elsif (/^\s+(.*?)\s+$===^\s+(.*?)\s+$/) {
# elsif (/^\s+(.*?)\s+$===^\s+(.*?)\s+$/m) {
# elsif (/^(.*?) === (.*?)$/sm) {
$items -> {$1} = $2;
}
}
return $items;