Verbs
As is typical of your typical imperative computer language, many
of the verbs in Perl are commands: they tell the Perl interpreter to do
something. On the other hand, as is typical of a natural language, the
meanings of Perl verbs tend to mush off in various directions depending
on the context. A statement starting with a verb is generally purely
imperative and evaluated entirely for its side effects. (We sometimes
call these verbs procedures, especially when
they’re user-defined.) A frequently seen built-in command (in fact,
you’ve seen it already) is the say
command:
say "Adam's wife is $wife{'Adam'}.";This has the side effect of producing the desired output:
Adam's wife is Eve.
But there are other “moods” besides the imperative mood. Some
verbs are for asking questions and are useful in conditionals such as
if statements. Other verbs translate
their input parameters into return values, just as a recipe tells you
how to turn raw ingredients into something (hopefully) edible. We tend
to call these verbs functions, in deference to
generations of mathematicians who don’t know what the word “functional”
means in normal English.
An example of a built-in function would be the exponential function:
my $e = exp(1); # 2.718281828459 or thereabouts
But Perl doesn’t make a hard distinction between procedures and functions. You’ll find the terms used interchangeably. Verbs are also sometimes called operators (when built-in), or subroutines (when user-defined).[17] But call them whatever you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access