<<< Date Index >>>     <<< Thread Index >>>

Re: Quote indentation string and multilevel quoting



On Fri, Apr 09, 2004 at 04:03:55AM +0200, Michael Kjorling wrote:
> On Apr 08 2004 16:06, dgc@xxxxxxxxxxxx sent:
> > I would look at $editor: perhaps set it to the name of a script that    
> > performs the transformation you want (using sed, perl, python, whatever
>
> Now there's an idea I hadn't thought of, but which makes a lot of
> sense. Thanks for the suggestion!
>
> For the benefit of the archives, here is the essense of what I came up
> with after a bit of experimenting:
>
>       perl -e 'while(<>) { while(/^(>+ )+/) { ~s:^(>+) (^>.+)?:$1$2:; } \
>       ~s:^(>+) *(^>+)?:$1 $2:; ~s:^(>*) +$:$1:; print; }'
>
> This little oneliner probably isn't the most efficient way of doing
> things, but it seems to get the job done without getting caught in any
> infinite loops at least.
 
I'm curious about the tildes before the substitution operators.  They're    
not necessary; you're actually doing a bitwise negation on the results of
each substitution.  :)  Also, in the first two substitutions, the second
parenthesized group will never match, because you're trying to match ^ in   
the middle of the line.
 
I think this one-liner also does what you want:
 
perl -pe '1 while s/^(>+) +>/$1>/'

 
Ronald