perl: swap -M example with -0, for multiline regex

For completeness: the -0 option is actually used to specify the input record separator (as an octal number).
Without it, the record separator is the newline character, i.e. the files are processed line by line
(which doesn't allow find-replace expressions that include newlines to work).

According to the [documentation](http://perldoc.perl.org/perlrun.html#Command-Switches),
using plain `-0` is not guaranteed to have the effect of parsing the entire file,
because if the file does contain characters with octal value equal to the parameter passed to (or implied by) the -0 option,
these characters will be treated as line breaks.
However, if the value exceeds 377<sub>8</sub> (i.e. 255), it won't be matched to characters on the file.
777 is the preferred convention within that exceptional range, as the highest value that keeps to 3 octal digits.

Here we're forgoing such details and using -0 anyway, since for most cases this will be enough.
coverage
Waldir Pimenta 2017-05-13 16:45:56 +01:00 committed by Agniva De Sarker
parent 1de00d2f11
commit dc9547925f
1 changed files with 4 additions and 4 deletions

View File

@ -14,10 +14,6 @@
`perl -e {{perl_statement}}`
- Import module before execution of a perl statement:
`perl -M{{module}} -e {{perl_statement}}`
- Run a Perl script in debug mode, using `perldebug`:
`perl -d {{script.pl}}`
@ -26,6 +22,10 @@
`perl -p -i -e 's/{{find}}/{{replace}}/g' {{filename}}`
- Run a multi-line find/replace expression on a file (i.e. including line breaks):
`perl -0 -p -i -e 's/{{foo\nbar}}/{{foobar}}/g' {{filename}}`
- Run a find/replace expression on a file, saving the original file with a given extension:
`perl -p -i'.old' -e 's/{{find}}/{{replace}}/g' {{filename}}`