What is the average value "at compile time" in perl scripts

I read this about perl:

Perl is an interpreted language and does not compile.

And I also see a conversation about at compile-timeand at run-time.

Especially when I look for use useand require, this shows the difference:

useusually loads the module at compile time, while it requireworks at runtime.

So my question is: Is Perl really compiling a script?
What is the average value "at compile time" in perl scripts?

+4
source share
3 answers

Perl . . perl -c ( - ).

perlrun:

Perl . - , . ( script, , .)

. , - / , , , .

, use strict; use warnings;, . , , - .

, - , , , , .

, , , , , , " ". Perl , - , / .

- , . , , .

+4

Perl- , . , Java , .

# B::Concise shows the opcode tree that results from compiling Perl code

$ perl -MO=Concise,-exec -e'print("Hello, world!\n") for 1..3;'
1  <0> enter
2  <;> nextstate(main 1 -e:1) v:{
3  <0> pushmark s
4  <$> const[IV 1] s
5  <$> const[IV 3] s
6  <#> gv[*_] s
7  <{> enteriter(next->b last->e redo->8) lKS/8
c  <0> iter s
d  <|> and(other->8) vK/1
8      <0> pushmark s
9      <$> const[PV "Hello, world!\n"] s
a      <@> print vK
b      <0> unstack v
           goto c
e  <2> leaveloop vK/2
f  <@> leave[1 ref] vKP/REFC
-e syntax OK

Perl ( perl, require, do EXPR eval EXPR), , .

use BEGIN, use BEGIN , .

# -c causes the main program to be compiled but not executed.

$ perl -c -E'
   say "abc";
   BEGIN { say "def"; }
   say "ghi";
'
def
-e syntax OK

$ perl -E'
   say "abc";
   BEGIN { say "def"; }
   say "ghi";
'
def
abc
ghi

.

$ perl -c -E'say "abc" "def";'
String found where operator expected at -e line 1, near ""abc" "def""
        (Missing operator before  "def"?)
syntax error at -e line 1, near ""abc" "def""
-e had compilation errors.

.

$ perl -c -E'$x={}; $x->[0]'
-e syntax OK

$ perl -E'$x={}; $x->[0]'
Not an ARRAY reference at -e line 1.
+5

See How Perl 5 Works . He claims that

There are two different stages to the execution of a Perl 5 program: compilation time and runtime.

He also describes the difference between compile timeand runtime.

+2
source

All Articles