Replacing two EOL chars by one

Is this language really necessary? I’m sure I’ve used these words myself,
but they’re certainly not appropriate in a public discussion.

I do not know the answer to your question, it really seems more like a
regexp question, rather than a problem with Perl. I hope someone who knows
the answer can respond, hopefully in more civil language.

Paul McGuire wrote:

I hope someone who knows the answer can respond, hopefully in more
civil language.

I’m sure that quite a few people know the answer, but most of them
have probably killfiled or decided to ignore him.

I hope that nobody provides an answer.

···


Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Gunnar Hjalmarsson noreply@gunnar.cc writes:

Paul McGuire wrote:

I hope someone who knows the answer can respond, hopefully in more
civil language.

I’m sure that quite a few people know the answer, but most of them
have probably killfiled or decided to ignore him.

I hope that nobody provides an answer.

And it’s crossposted to numerous groups that have nothing to do with
perl.

···


Rahul Jain
rjain@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist

“Paul McGuire” ptmcg@austin.rr.com writes:

Is this language really necessary? I’m sure I’ve used these words myself,
but they’re certainly not appropriate in a public discussion.

We don’t get the usenet “in color” around here, so I guess that this
languages reflected the fuming hot in frustration state of the OP. I
guess that you could measure the quality of a design and its
documentations by the inverse of the number of posts related to it
using such language.

When we’ll have video-usenet, I guess language will be more proper,
but we’ll be seeing keyboads and screens flying out of the windows
more often.

I do not know the answer to your question, it really seems more like a
regexp question, rather than a problem with Perl. I hope someone who knows
the answer can respond, hopefully in more civil language.

Even with sed I find difficult to do that.

On the other hand, with emacs it’s quite simple:

M-x replace-string RET C-q C-j C-q C-j RET C-q C-j RET

···


Pascal_Bourguignon . * * . * .* .
http://www.informatimago.com/ . * . .*
There is no worse tyranny than to force * . . /\ ( . *
a man to pay for what he does not . . / .\ . * .
want merely because you think it .. / * \ . .
would be good for him. – Robert Heinlein . /
o \ .
http://www.theadvocates.org/ * ‘’‘||’‘’ .
SCO Spam-magnet: postmaster@sco.com ******************

Pascal Bourguignon spam@thalassa.informatimago.com:

Even with sed I find difficult to do that.

If you want to remove blank lines, then sed ‘/^$/d’ will do. If, on
the other hand, you actually want to compress pairs of newlines into
single newlines (as I think the specification may have said), something
a bit more complicated is required. I think that sed ‘N;P;/\n$/d;D’
will do it.

Jesse

Pascal Bourguignon spam@thalassa.informatimago.com:

Even with sed I find difficult to do that.

If you want to remove blank lines, then sed ‘/^$/d’ will do. If, on
the other hand, you actually want to compress pairs of newlines into
single newlines (as I think the specification may have said), something
a bit more complicated is required. I think that sed ‘N;P;/\n$/d;D’
will do it.

If you want to use Perl or Ruby, these are equivalent to the first sed
solution:

ruby -ne 'print unless /^$/'
perl -ne 'print unless /^$/'

In Ruby you might also use:

ruby -pe 'next if /^$/'

The equivalent doesn’t work in Perl, probably because -p puts the
implicit print statement in a “continue” block, which gets executed
before the loop is restarted by “next”.

If you’re doing this on a huge file and care about speed, sed will
be slightly faster than Perl and Perl will blow Ruby away. Because
I was curious, I tried writing it in C to see if I could beat sed.
My first attempt was slightly slower (!), but my second attempt ran
much faster than sed; unfortunately, it also took 30 minutes and
34 lines.

Jesse