2016-11-05 19:14:19 +00:00
|
|
|
# perl
|
|
|
|
|
|
|
|
> The Perl 5 language interpreter.
|
2019-05-29 14:53:42 +01:00
|
|
|
> More information: <https://www.perl.org>.
|
2016-11-05 19:14:19 +00:00
|
|
|
|
2016-11-05 19:17:40 +00:00
|
|
|
- Parse and execute a Perl script:
|
2016-11-05 19:14:19 +00:00
|
|
|
|
|
|
|
`perl {{script.pl}}`
|
|
|
|
|
2016-11-05 19:17:40 +00:00
|
|
|
- Check syntax errors on a Perl script:
|
2016-11-05 19:14:19 +00:00
|
|
|
|
2016-11-05 19:17:40 +00:00
|
|
|
`perl -c {{script.pl}}`
|
2016-11-05 19:14:19 +00:00
|
|
|
|
2019-11-12 08:50:23 +00:00
|
|
|
- Parse and execute a Perl statement:
|
2016-11-05 19:14:19 +00:00
|
|
|
|
2016-11-05 19:17:40 +00:00
|
|
|
`perl -e {{perl_statement}}`
|
2016-11-05 19:14:19 +00:00
|
|
|
|
2016-11-05 19:17:40 +00:00
|
|
|
- Run a Perl script in debug mode, using `perldebug`:
|
2016-11-05 19:14:19 +00:00
|
|
|
|
|
|
|
`perl -d {{script.pl}}`
|
2017-04-15 16:48:00 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
- Edit all file lines [i]n-place with a specific replacement [e]xpression and save a file with a new extension:
|
2017-04-15 16:48:00 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
`perl -p -i'.{{extension}}' -e 's/{{regular_expression}}/{{replacement}}/g' {{path/to/file}}`
|
2017-04-15 16:48:00 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
- Run a multi-line replacement [e]xpression on a file, and save the result in a specific file:
|
2017-04-15 16:48:00 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
`perl -p -e 's/{{foo\nbar}}/{{foobar}}/g' {{path/to/input_file}} > {{path/to/output_file}}`
|
2017-05-13 17:01:12 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
- Run a regular [e]xpression on stdin, printing matching [l]ines:
|
2017-05-13 17:01:12 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
`cat {{path/to/file}} | perl -n -l -e 'print if /{{regular_expression}}/'`
|
2019-09-24 14:00:09 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
- Run a regular [e]xpression on stdin, printing only the first capture group for each matching [l]ine:
|
2019-09-24 14:00:09 +01:00
|
|
|
|
2022-04-30 08:09:53 +01:00
|
|
|
`cat {{path/to/file}} | perl -n -l -e 'print $1 if /{{before}}({{regular_expression}}){{after}}/'`
|