S
sbk
hi,
how do i search for consecutive blank lines and replace with something
else?
I thought that "s/\n\n/foo/;" would work ... but obviously not.
guru> cat test
#!/opt/vdops/bin/perl
use diagnostics;
use strict;
use warnings;
open INPUT, "<foo" or die "Can't open foo: $!";
while (<INPUT>) {
s/\n\n/dog\n/;
print;
}
close INPUT;
guru> cat foo
Frogs live in ponds. Hit 'Enter' twice.
So do toads. Hit 'Enter' three times.
And newts live near ponds. Don't hit 'Enter' any more.
guru> ./test
Frogs live in ponds. Hit 'Enter' twice.
So do toads. Hit 'Enter' three times.
And newts live near ponds. Don't hit 'Enter' any more.
so that didn't work ... but searching for a single "\n" works just
fine.
guru> cat test
#!/opt/vdops/bin/perl
use diagnostics;
use strict;
use warnings;
open INPUT, "<foo" or die "Can't open foo: $!";
while (<INPUT>) {
s/\n/dog\n/;
print;
}
close INPUT;
guru> ./test
Frogs live in ponds. Hit 'Enter' twice.dog
dog
So do toads. Hit 'Enter' three times.dog
dog
dog
And newts live near ponds. Don't hit 'Enter' any more.dog
guru>
what is it about two "\n" in a row which requires special handling?
perl-5.8.6
--sk
stuart kendrick
fhcrc
how do i search for consecutive blank lines and replace with something
else?
I thought that "s/\n\n/foo/;" would work ... but obviously not.
guru> cat test
#!/opt/vdops/bin/perl
use diagnostics;
use strict;
use warnings;
open INPUT, "<foo" or die "Can't open foo: $!";
while (<INPUT>) {
s/\n\n/dog\n/;
print;
}
close INPUT;
guru> cat foo
Frogs live in ponds. Hit 'Enter' twice.
So do toads. Hit 'Enter' three times.
And newts live near ponds. Don't hit 'Enter' any more.
guru> ./test
Frogs live in ponds. Hit 'Enter' twice.
So do toads. Hit 'Enter' three times.
And newts live near ponds. Don't hit 'Enter' any more.
so that didn't work ... but searching for a single "\n" works just
fine.
guru> cat test
#!/opt/vdops/bin/perl
use diagnostics;
use strict;
use warnings;
open INPUT, "<foo" or die "Can't open foo: $!";
while (<INPUT>) {
s/\n/dog\n/;
print;
}
close INPUT;
guru> ./test
Frogs live in ponds. Hit 'Enter' twice.dog
dog
So do toads. Hit 'Enter' three times.dog
dog
dog
And newts live near ponds. Don't hit 'Enter' any more.dog
guru>
what is it about two "\n" in a row which requires special handling?
perl-5.8.6
--sk
stuart kendrick
fhcrc