in reply to Re: removing redundantwhitespace
in thread removing redundantwhitespace

This doesn't collapse "a \nb" into "a\nb". It's difficult to tell from the desired output (because I can't see spaces at the ends of lines …), but it seems that the poster may have wanted that to happen.

Replies are listed 'Best First'.
Re^3: removing redundantwhitespace
by GrandFather (Saint) on Sep 13, 2008 at 22:03 UTC

    I thought I caught that case but, as you suggest, the white space on the end of the line is hard to see! The following simplifies the regex and fixes that case at the cost of complicating the substitution:

    $str =~ s/((^|\s)\s*)/length ($2) ? (-1 < index ($1, "\n") ? "\n" : ' +') : ''/ges;

    Oh, and it replaces tabs with spaces.


    Perl reduces RSI - it saves typing