forked from cheat/cheatsheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperl
78 lines (56 loc) · 1.94 KB
/
perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
tags: [ perl ]
---
See https://perldoc.perl.org/perlrun
# View the perl version (long and short version):
perl -v
perl -V
# Run a program:
perl <program> [args]
# Syntax check a program:
perl -cw <program>
# Force warnings everywhere in the program:
perl -W <program>
# Add path1 to the module search path:
# The PERL5LIB env var does this too
perl -I <path1> <program> [args]
# Start the program in the perl debugger:
# See https://perldoc.perl.org/perldebug)
perl -d <program>
# Specify the program text as the argument to -e:
perl -e <program_text>
perl -e 'print "Hello World!\n"'
# Enable Unicode:
perl -C -e <program_text>
# Specify the program text and enable new features:
perl -E 'say "Hello World!"'
# Specify the program text and enable new features:
perl -M<module>[=import,list] -E <program_text>
# Compile then decompile a program with B::Deparse:
perl -MO=Deparse -E <program_text>
# Process files line-by-line (output on your own):
perl -ne <program_text> [files]
# Process files line-by-line (output $_ at each loop iteration):
perl -pe <program_text> [files]
# Read an entire file (or STDIN) into one big string.
# With v5.36 and later, -g is the same as -0777
perl -0777 -ne <program_text> [files]
perl -0777 -pe <program_text> [files]
perl -g -pe <program_text> [files]
# Split input lines on whitespace with -a, put into @F:
perl -ane <program_text>
# -a implies -n:
perl -ae <program_text>
# Splits lines on alternate separator with -F:
perl -aF<separator> -e <program_text>
# In-place editing with -p:
perl -pe <program_text> [files]
# In-place editing with -p and backup original with -i:
perl -pie <program_text> [files]
perl -pi.bak -e <program_text> [files]
# Replace string "\n" to newline:
echo -e "foo\nbar\nbaz" | perl -pe 's/\n/\\n/g;'
# Replace newline with multiple line to space:
cat test.txt | perl -0pe "s/test1\ntest2/test1 test2/m"
# Replace double newlines with single newline:
perl -pe '$/=""; s/(\n)+/$1/' my-file