in reply to Re: Global Whitespace Delete
in thread global whitespace delete

that's really fantastic, many thanks. I have modified it to:
s/((?:"[^"]*?")|(?:'[^']*?'))|(\s+)/$2?$2 ne"\n"?" ":"\n":$1/ge;
so that the "\n" on the end of the line isn't changed to ' '.
And now I will read more about ?: and try to understand it. :-)
btw. It was no homework as BrentDax suspects, it's just a single line in a convertscript for comfiche jobs.
Thanks
----------------------------------- --the good, the bad and the physi-- -----------------------------------

Replies are listed 'Best First'.
Re^3: global whitespace delete
by tadman (Prior) on Jul 31, 2001 at 14:27 UTC
    I'm not sure where BrentDax got the homework idea. A little quick to judge, is all, I suppose.

    Your comparison is peculiar. You might want to specify a set instead of \s+, such as:
    s/((?:"[^"]*?")|(?:'[^']*?'))|([ \t]+)/$2?" ":$1/ge;
    The set of space and tab is probably more efficient than asking for more than you want, and then discarding the extras. \s by default contains tab, space, and newline. Since you have no use for newline, just don't ask for it.