replacing two EOL chars by one
Sara
genericax at hotmail.com
Mon Dec 22 16:17:24 EST 2003
tiltonj at erols.com (Jay Tilton) wrote in message news:<3fe4bd0e.68951468 at news.erols.com>...
> xah at xahlee.org (Xah Lee) wrote:
>
> : i have a bunch of java files that has spaced-out formatting that i
> : want to get rid of. I want to replace two end of line characters by
> : one end of line characters. The files in question is unix, and i'm
> : also working under unix, so i did:
> :
> : perl -pi'*~' -e "s@\n\n@\n at g" *.java
> :
> : but this to no avail.
>
> Of course it's not.
>
> Perl's -p switch processes one line at a time. A line cannot have more
> than one newline character.
>
> Perl's "paragraph" reading might be useful to you, where any number of
> consecutive newline characters mark the end of a record. See "$/" in
> perlvar for details.
>
> perl -i'*~' -lpe "BEGIN{$/=''}" *.java
>
> : after many minutes of checking and rechecking and lots of trial and
> : error with frustration, i realized that the fucking perl to my
> : expectations again cannot do this simple fucking thing.
>
> Complete nonsense. Don't blame your own incompetence on Perl.
>
> : Fucking stupid perl
> : documentation and Larry Wall moron who is i believe incapable of
> : writing clearly and logically in English masquerading as humor.
>
> If you feel you can explaint it more clearly, quit bellyaching about it and
> submit a documentation patch.
>
> Preferrably one that is less petulant and profane than your article.
> Frustration is no excuse for incivility.
is incivility a word? Curious. Anyhow, if I understand this you want
to replace two \n's with one? How about this (untested) code:
die "Perl is ever so much smarter than Java\n" unless open F,
'myfile';
my @f = <FILE>
close F;
$f = join '', at f;
$f =~ s/(\n)\n/$1/gs;
die "Hmm this file cant be opened for writing\n" unless open F,
'>myfile';
print F $f;
close F;
print "Perl does it again!\n\n";
More information about the Python-list
mailing list