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        


In reply to Re^4: removing redundantwhitespace (too far) by tye
in thread removing redundantwhitespace by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.