Skip to content

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

Open
@jubilatious1

Description

@jubilatious1

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions