in reply to Re^3: removing redundantwhitespace (too far)
in thread removing redundantwhitespace

The first one works except it leaves the trailing newline:

It was supposed to leave a trailing newline.

The other ones are, of course, meant to do something different. Besides omitting the /e, I had the test backward. But the real problem with that is that reversing the test means reversing "and" vs "or" which leaves this approach "bogged down in unfortunate complexities", as usual.

Yes, the last one appears to do what was intended. I didn't have 5.010 handy at the time I wrote that.

I'll continue to wonder if there is a reasonable, (and warning-free would be nice) single-pass regex for this that doesn't require 5.010 features.

Note that the (even less compelling) translation to pre-5.010 would be:

s{(^)?\s+(\z)?}{ defined $1 || defined $2 ? '' : ' ' }gex

and that this even leaves a trailing space on 5.8.3 because of a quirk (aka "bug") there:

$ perl5.8.3 -del DB<1> x "hi" =~ /i\z/ 0 1 DB<2> x "hi" =~ /(i)(\z)?/ 0 'i' 1 undef $ perl5.10 -del DB<1> x "hi" =~ /(i)(\z)?/ 0 'i' 1 ''

Thanks for pointing those issues out.

- tye