On Dec 30, 2003, at 8:45 AM, Kevin Old wrote: [..]
$ko =~ s/\r/\\page/g; # change returns to \page
$ko =~ s/\f//g; # remove formfeeds
$ko =~ s/\t/\\tab/g; # change tabs to \tab
$ko =~ s/\\\\/\\/g; # escape backslashes
$ko =~ s/{/\\{/g; # escape left curly
$ko =~ s/}/\\}/g; # escape right curly
$ko =~ s/\n/\n\\par /g; # replace newlines with \n\par
$ko =~ s/\\par\s+\n\\par\s+\n\\par\s+\n+/\\par \n/migs; # cosolidate
"blank" lines
$ko =~ s/\\f0\\fs22\n\\page/\\f0\\fs22\n\\par /migs; # remove first page
break


This is not so much for laziness, but is more for learning what/how to
consolidate.

Sometimes 'consolidation' does not save the nation.


but the lines that amuse me are

$ko =~ s/\n/\n\\par /g; # replace newlines with \n\par
$ko =~ s/\\par\s+\n\\par\s+\n\\par\s+\n+/\\par \n/migs; # cosolidate

first we put some stuff in and then decide to rip it out...


What if we tried to solve the 'blank line' problem first?

There is also that minor buggaboo about
        "\r\n" - our friends <CR><LF>

that first line in the package would take say

Joe\r\n\r\nBob

and convert it into

Joe\page\n\page\nBob

and then we hit the \\par packer
and would get to

Joe\page\n\par\page\n\parBob

and now we do not see our 'empty line'

So I would always start with the

        take out what we want to remove
        then dither with what is left.

Say something along the line of

$ko =~ s/\r\n\s*\r\n/\r\n/mig ;

that would take us from our initial state to

Joe\r\nBob

and perchance a bit more sanity in the process.

Logically the next line would do the remove
of things like the \f and then we start
worrying about the rest of the substitutions.

I presume you have already peeked

perldoc perlretut

as well as picked up the book on mastering
regular expressions.

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to