Terminology


In general, the terminology used in Perl isn't that different from that used to describe other programming languages. However, there are a few terms with slightly peculiar meanings. In addition, as Perl has evolved, some terminology has faded from fashion and some new terminology has been added. Here, I will explain a few of the more nitpicky entries in the Perl glossary.

The terms array and list have precise meanings in Perl. However, those meanings are really only clear to people who are somewhat familiar with the internals of Perl, and it is not often that the differences are evident. Basically, an array is a Perl data structure with more or less permanently allocated storage, which may or may not have a name associated with it. A list, on the other hand, is a bunch of values on the run-time stack. Perl converts lists and arrays back and forth with indifference. An array used in a list context becomes a list of values; a list assigned to an array variable becomes an array. The difference is apparent only in a limited number of circumstances. You cannot, for example, pop from a list.

Associative array is an obsolete pre-Perl 5 term . Around the advent of Perl 5, the Perl Illuminati tired of this elaborate seven-syllable compound word and replaced it with the much more succinct hash . There is no difference in meaning.

An operator in Perl is a parentheses-less syntactic construct. (But the arguments to an operator may, of course, be contained in parentheses.) A list operator is an identifier followed by a list of elements separated by commas:

 print "Hello", chr(44)," world!\n"; 

print is a list operator.

A function in Perl is an identifier followed by a pair of parentheses that completely enclose the arguments:

 print ("Hello", chr(44), " world!\n"); 

print is also a function.

Now, you may have just noticed a certain similarity between list operators and functions. In Perl, there is no difference other than the syntax used. I will generally use the term "operator" when I refer to Perl built-ins like print and open , but may use "function" occasionally. There is no particular difference in meaning.

The proper way to refer to a subroutine written in Perl is, well, subroutine . Of course, "function," "operator," and even "procedure" will make acceptable literary stand-ins.

Although the term method is dealt with thoroughly in Item 49, I should discuss it briefly here. Perl methods are really subroutines written to conform to certain conventions, which are neither required nor recognized by Perl. However, Perl does have a special method call syntax that is used to support object-oriented programming. A good way of defining the (somewhat elusive ) difference is by stating that a method is a subroutine that is intended to be called via method call syntax.

A Perl identifier is a "C symbol"a letter or underscore followed by zero or more letters , digits, or underscores. Identifiers are used to name Perl variables . Perl variables are identifiers combined with the appropriate punctuation, for example, $a or &func .

Although this is not strictly in keeping with the usage in the internals of Perl, I will use the term keyword to refer to the small number of identifi-ers in Perl that have distinctive syntactic meanings, for example, if and while . Other identifiers like print and oct that have ordinary function or operator syntax will be called built-ins , if anything.

An lvalue (pronounced "ell value") is a value that can appear on the left hand side of an assignment statement. This is the customary meaning of the term; however, there are some unusual constructs that act as lvalues in Perl, for example, the substr operator.

Localizing a variable means creating a separate scope for it that applies through the end of the enclosing block or file. Special variables must be localized with the local operator. [2] Ordinary variables can be localized with either my or local (see Item 23). I will say "localize with my " when it makes a difference.

[2] Future versions of Perl may add the ability to localize special variables in a different way, probably with my .



Effective Perl Programming. Writing Better Programs with Perl
Effective Perl Programming: Writing Better Programs with Perl
ISBN: 0201419750
EAN: 2147483647
Year: 1996
Pages: 116

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net