-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspecial_functions.pl
51 lines (44 loc) · 1.19 KB
/
special_functions.pl
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
use strict;
use warnings;
# This is just the demo of how special functions work inside perl code
# https://perldoc.perl.org/perlmod.html#BEGIN%2c-UNITCHECK%2c-CHECK%2c-INIT-and-END
print "10. Ordinary code runs at runtime.\n";
END {
print "16. So this is the end of the tale.\n";
}
INIT {
print " 7. INIT blocks run FIFO just before runtime.\n";
}
UNITCHECK {
print " 4. And therefore before any CHECK blocks.\n";
}
CHECK {
print " 6. So this is the sixth line.\n";
}
print "11. It runs in order, of course.\n";
BEGIN {
print " 1. BEGIN blocks run FIFO during compilation.\n";
}
END {
print "15. Read perlmod for the rest of the story.\n";
}
CHECK {
print " 5. CHECK blocks run LIFO after all compilation.\n";
}
INIT {
print " 8. Run this again, using Perl's -c switch.\n";
}
print "12. This is anti-obfuscated code.\n";
END {
print "14. END blocks run LIFO at quitting time.\n";
}
BEGIN {
print " 2. So this line comes out second.\n";
}
UNITCHECK {
print " 3. UNITCHECK blocks run LIFO after each file is compiled.\n";
}
INIT {
print " 9. You'll see the difference right away.\n";
}
print "13. It only _looks_ like it should be confusing.\n";