Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a challenge

14 views
Skip to first unread message

Marc Horowitz

unread,
Mar 31, 1992, 5:24:15 PM3/31/92
to
A friend asked me to write the shortest script I could to collapse
multiple blank lines down to one. The best I could do was:

perl -ne '0+$c|($c=/\S/)&&print'

Now, this depends on order of evaluation, and precedence, and other
stuff. Elegance was not a requirement.

Anyway, the question is this: Why is the 0+ necessary? The best I
can guess is that it provides a scalar context, but shouldn't the | do
that? I could see things getting confused if perl was using | for bit
vector manipulation, but since I'm not using vec, I don't think that's
happening, either. So, what's going on?

(As an aside, there's a shorter answer:

perl -00ne '/\S/&&print'

This has the interesting property that it sort of "fuzzy": it reduces
multiple blank lines to either one or two blank lines. But it's
really short :-)

Marc

0 new messages