Tutorial
Command line flags and parameters
For the official documentation visit perldoc perlrun or the same on MetaCPAN
-vprint the version of perl--versionthe same as-v-Vprint defailed information about the perl. (e.g. compilation flags)-eExecute the perl code that follows this flag.-EJust like-e, but enable all extra features add to Perl since the 5.10 release.-nWrap the code provided using the-eor-Eflags in awhileloop to execute the code on every line of every file. The current line is in$_.-pDo the same as-nand also print the possibly modified content of the current line stored in$_.-iin-place editing (replace the processed file by the output)-i.bakin-place editing with backup
Code snippets we use in the book
- Regex (or regexp or Regular Expression)
/bla/orm/bla/orm{bla}whereblacan be any regular expression. See perlre or on MetaCPAN. - Substitution with regex
s/bla/replacement/. if- conditionalnot- boolean negationunlessthe same asif not$.the current line number starting from 1
Best practices
- Use version control (e.g. git) on all of your file, including your data files.
- When doing in-place editing, if you don’t have version control of the files you are editing then create a backup either before the process or during the process using
-i.bak - Quotes: On Linux and macOS we usually use single-quotes around the perl code of the oneliner. On MS Windows AFAIK you cannot do that and thus there the outer quotes are double-quotes. This also means that the quotes, if used in the code, will need to be used differently. Therefore in general it is better to use
q()instead of single quotes andqq()for double quotes.