Concepts of Programming Languages

(Sean Pound) #1

2.18 Scripting Languages


Scripting languages have evolved over the past 25 years. Early scripting
languages were used by putting a list of commands, called a script, in a file
to be interpreted. The first of these languages, named sh (for shell), began
as a small collection of commands that were interpreted as calls to system
subprograms that performed utility functions, such as file management and
simple file filtering. To this were added variables, control flow statements,
functions, and various other capabilities, and the result is a complete pro-
gramming language. One of the most powerful and widely known of these
is ksh (Bolsky and Korn, 1995), which was developed by David Korn at Bell
Laboratories.
Another scripting language is awk, developed by Al Aho, Brian Kernighan,
and Peter Weinberger at Bell Laboratories (Aho et al., 1988). awk began as a
report-generation language but later became a more general-purpose language.

2.18.1 Origins and Characteristics of Perl


The Perl language, developed by Larry Wall, was originally a combination
of sh and awk. Perl has grown significantly since its beginnings and is now a
powerful, although still somewhat primitive, programming language. Although
it is still often called a scripting language, it is actually more similar to a typical
imperative language, since it is always compiled, at least into an intermediate
language, before it is executed. Furthermore, it has all the constructs to make
it applicable to a wide variety of areas of computational problems.
Perl has a number of interesting features, only a few of which are men-
tioned in this chapter and later discussed in the book.
Variables in Perl are statically typed and implicitly declared. There are
three distinctive namespaces for variables, denoted by the first character of
the variables’ names. All scalar variable names begin with dollar signs ($), all
array names begin with at signs (@), and all hash names (hashes are briefly
described below) begin with percent signs (%). This convention makes vari-
able names in programs more readable than those of any other programming
language.
Perl includes a large number of implicit variables. Some of them are used
to store Perl parameters, such as the particular form of newline character or
characters that are used in the implementation. Implicit variables are com-
monly used as default parameters to built-in functions and default operands
for some operators. The implicit variables have distinctive—although cryptic—
names, such as $! and @_. The implicit variables’ names, like the user-defined
variable names, use the three namespaces, so $! is a scalar.
Perl’s arrays have two characteristics that set them apart from the arrays
of the common imperative languages. First, they have dynamic length, mean-
ing that they can grow and shrink as needed during execution. Second, arrays
can be sparse, meaning that there can be gaps between the elements. These

2.18 Scripting Languages 95
Free download pdf