[Cialug] Perl regex
Daniel A. Ramaley
daniel.ramaley at DRAKE.EDU
Tue Jun 19 10:57:13 CDT 2007
Since we're posting brain teasers, here's what i'm having trouble with:
Is there a way to design a Perl s/// regex such that after each
replacement it starts searcing for the next replacement at the
beginning of where it found the previous match instead of after the
previous match?
What i'm trying to accomplish is to take files that look something like
this:
# Comment
AB=some text
CDE=text
CDE= more text
CDE=even more
F=foo
GH=bar,
GH= baz
And concatenate the continued lines together, so after processing it
looks like this:
# Comment
AB=some text
CDE=text more texteven more
F=foo
GH=bar, baz
Here's what i have so far, with the entire file contained in $data (i
already had to slurp the whole thing for other processing that was done
to it first):
1 while $data =~ s/^(([^#][^=]*)=.*)\n\2=/$1/gmo;
That works, but if there is a way to tell the regex parser to not
advance its internal pointer after each match, then i can get rid of
the useless while loop. (As it is now, without the while it only works
on lines that have been split into 2 (such as "GH" in the example) but
not lines split into 3 or more (such as "CDE").)
------------------------------------------------------------------------
Dan Ramaley Dial Center 118, Drake University
Network Programmer/Analyst 2407 Carpenter Ave
+1 515 271-4540 Des Moines IA 50311 USA
More information about the Cialug
mailing list