Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small error in "removing consecutive blank lines" code; two suggested fixes #35

Open
jubilatious1 opened this issue Sep 17, 2019 · 0 comments

Comments

@jubilatious1
Copy link

jubilatious1 commented Sep 17, 2019

Remove all consecutive blank lines, leaving just one

perl6 -e '$*ARGFILES.slurp.subst(/\n+/, "\n\n", :g).say' example.txt

Actually, the code above literally says to take any single "\n" and replace it with "\n\n", so the overall effect is to convert a single-spaced document into a double-spaced document. However, the "+" quantifier in "\n+" in fact does enable the intended effect of collapsing multiple consecutive blank lines (>2) into just one blank line.

Here are two examples (below) that collapse multiple consecutive blank lines into just one blank line, without altering the over-all document spacing in either a single-spaced or double-spaced document:

perl6 -e '$*ARGFILES.slurp.subst(/\n\n+/, "\n\n", :g).say' example.txt

perl6 -e '$*ARGFILES.slurp.subst(/\n**2..*/, "\n\n", :g).say' example.txt

These two examples are just an intermediate fix for now. Obviously one would want more general code where the user can define "N" in an ostensibly "N-spaced" document, so it gets scanned to remove any extra ">N-spacing" returns (e.g. removing quadruple-spacing in a triple-spaced document).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant