next up previous contents
Next: How is perl different Up: Introduction Previous: Interpreter vs. Compiler   Contents

How is Perl like other Languages?

If you're familiar with C, awk, sed or any of the common UNIX shells (sh, bash, csh, etc.), you'll recognize lots of perl code the first time you see it. Most of the basic control structures in perl are similar or identical to those of C, and many of the interactions with the operating system are identical to those of the shell scripts. Like C, all perl statements must end with a semi-colon (;), square braces ([ and ]) are used for array indexing, and curly braces ({ and }) are used to group blocks of statements together. Pattern matching and substitution, one of perl's greatest strengths, uses a syntax very similar to sed's.

Perl uses the same mechanism for comments as do the shell scripts, namely any text appearing on a line after a pound sign (#) is treated as a comment. And like shell scripts, perl statements are executed when they are encountered in a program, not when some particular function (like main() in C) is invoked.

Besides the constructs borrowed from shell scripts, awk and sed, perl is primarily a functional language - you accomplish tasks by calling functions, which either do what you want, or return a value which you can store in a variable, and further manipulate. Thus, one good way to write perl programs is to identify the key tasks you need to perform and either find existing functions to do those tasks, or to write the functions yourself. Writing functions in perl is very similar to writing ordinary programs, and in this way, perl encourages modular programming.

Perl is also capable of producing object-oriented programs. In object oriented programs, certain data is marked as belonging to a particular class (``blessed'' in perl lingo), and methods are written to operate on that data. While perl provides the tools to produce object-oriented programs, you never need to write your programs this way. Like so much else in perl, it is one of many options available to you when trying to solve a particular problem.


next up previous contents
Next: How is perl different Up: Introduction Previous: Interpreter vs. Compiler   Contents
Phil Spector 2002-10-18