silence has asked for the wisdom of the Perl Monks concerning the following question:

I was searching for a way to remove multiple empty lines with a single empty line and came across this neat little command line trick. Works perfect, but I do not understand how the command works. perl -00pe "" inputfile > outputfile

Replies are listed 'Best First'.
Re: command line -00 option
by Zaxo (Archbishop) on Nov 04, 2002 at 20:16 UTC

    From perlrun:

    -0[digits]
    specifies the input record separator ("$/") as an octal number...
    ...The special value 00 will cause Perl to slurp files in paragraph mode. ...

    "Paragraph mode" is the term for what you wanted.

    After Compline,
    Zaxo

      Thanks! I am trying to understand what really is happening. Can you point me to someplace where I can read more about this specific option ?
        Click on the "perlrun" hyperlink in his reply and it will take you where you can read more about options.
Re: command line -00 option
by jmcnamara (Monsignor) on Nov 04, 2002 at 23:20 UTC

    The -0 command line option sets $/, the input record separator. The special value -00 sets $/ = ''.

    When $/ is set to the null string, like this, it has the effect of using one or more blank lines as the record separator.

    However, it still delimits the input records with \n\n. So in effect \n\n+ becomes \n\n. Take for instance the following input file (where $ represents a newline):

    These are the days.$ $ $ $ $ These are the days.$ $ $ $ These are the days.$

    Filtering it through the following program shows how the records are delimited:

    #!/usr/bin/perl -00n s/\n/\$/g; print "<$_>\n"; __END__ Prints: <These are the days.$$> <These are the days.$$> <These are the days.>

    Some of this is explained in perlrun and some in perlvar.

    --
    John.

      Thanks for the explanation. Very helpful.