I\'m reading Beginning Perl by Simon Cozens and in Chapter 8 - Subroutines he states that \"subroutines\" are user functions, while print
,
print
, open
, split
are not subroutines. They do not result in sub calls. They are not even present in the symbol table (in main::
or otherwise, although you can refer to them as CORE::split
, etc), and one cannot get a reference to their code (although work is being done to create proxy subs for them in CORE::
for when you want to treat them as subroutines). They are operators just like +
.
$ perl -MO=Concise,-exec -e'sub f {} f()'
1 <0> enter
2 <;> nextstate(main 2 -e:1) v:{
3 <0> pushmark s
4 <#> gv[*f] s
5 <1> entersub[t3] vKS/TARG,1 <--- sub call
6 <@> leave[1 ref] vKP/REFC
-e syntax OK
$ perl -MO=Concise,-exec -e'split /;/'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 > pushre(/";"/) s/64
4 <#> gvsv[*_] s
5 <$> const[IV 0] s
6 <@> split[t2] vK <--- not a sub call
7 <@> leave[1 ref] vKP/REFC
-e syntax OK
$ perl -MO=Concise,-exec -e'$x + $y'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 <#> gvsv[*x] s
4 <#> gvsv[*y] s
5 <2> add[t3] vK/2 <--- Just like this
6 <@> leave[1 ref] vKP/REFC
-e syntax OK
They are known by a variety of names:
And most are considered to be one of the following:
Subroutines are often called functions (as they are in C and C++), so "function" is an ambiguous word. This ambiguity appears to be the basis of your question.
As for while
, for
, unless
, etc, they are keywords used by flow control statements
while (f()) { g() }
and statement modifiers
g() while f();