Feed on
Subscription

The 14th chapter Perl5 Bao He module

First, require function

May divide with the require function the procedure Cheng Duoge the document and founds the function storehouse. For example, has in myfile.pl defines the good Perl function, available sentence require (“myfile.pl”); Contains in the procedure. When the Perl interpreter sees this sentence, in built-in ray variable @INC assigns in the table of contents seeks for document myfile.pl. If has found, in this document's sentence is carried out, otherwise program termination and output error information:

Can't find myfile.pl in @INC

As the subroutine call parameter, in the document the last expression's value becomes the returns value, the require function examined whether it is zero, if is zero terminates. For example the myfile.pl final sentence is:

print (“hello, world! n”);
$var = 0;

The 13th chapter Perl object-oriented programming

This chapter introduced how to use Perl to program the (OOP) characteristic object-oriented and how to construct the object, but also includes inherits, contents and so on method heavy load and data encapsulation.

First, module synopsis

Module (module) is Perl wraps (pachage). In Perl object based on to package in data item quotation. (quotation sees the xth chapter of quotation).

For details sees http://www.metronet.com/'s perlmod and perlobj.

The 12th chapter in Perl5 quotation/indicator

First, quotation synopsis

The quotation is an indicator, may aim at the variable, the array, the Hasche table (also to be called connection array) even the subroutine. Pascal or the C programmer should to quotes (i.e. indicator) the concept be very familiar, the quotation is some value address, is decided to its use by the programmer and the language stipulation. In Perl, may be called the quotation the indicator, the two are general, non-difference. The quotation is very useful in the foundation complex data aspect.

In Perl5 two kind of quotation type for hard quotation and mark quotation. The mark quotation includes the variable name, it to movement when founds the variable name and locates is very useful, basically, the mark quotation looks like the filename or in the UNIX system's soft link. But quotes hardly looks like in filing system's hard link.

The 11th chapter filing system

This chapter says the function has used the UNIX operating system's characteristic most, when the non-UNIX system, some functions possibly does not have the definition or has the different working, the use please to examine the Perl on-line documents.

First, document input/output function

This festival narrates from the document reads the information and to the file write information built-in storehouse function.

1st, basic I/O function

The tenth chapter formatted output

We already saw the primitive formatted text will not have output the document with the print function, this chapter narrated how to use function write and the printing form produces formatted the output.

Second, demonstration printing form

The printing form's demonstration has two steps:

1st, $~ supposes the form which the system variable must use

2nd, transfer function write

For example:

The ninth chapter connection array/Hasche table

First, ray variable limit

Says in front in the ray variable, may through subscript visit element. For example, the following sentence visit array @array third element:

$scalar = $array[2];

Although the array is very useful, but they have a remarkable flaw, which element storage namely very difficult to remember any content. If we write the number of times which in a routine calculation some document the first letter capital letter's word appears, realizes with the array is quite difficult, the procedure code is as follows:
...

Eighth stamp procedure

First, definition

The subroutine namely carries out a special assignment section of separation code, it may cause the reduced redundant code, and causes the procedure legible. In PERL, the subroutine may appear in procedure any place. The definition method is:
...

The seventh chapter control structure

First, condition judgment

if () {

}
elsif () {

}

else {

}

Second, circulation:

1st, while circulation

while () {

}

2nd, until circulation

until () {

The sixth chapter pattern matching

First, synopsis

The pattern refers to the specific sequence character which seeks in the string of character, includes by the backlash: /def/ is pattern def. Its usage like union function split divides into the string of character with some pattern many words: @array = split (//, $line);

Second, match instruction character =~! ~

the =~ examination matches whether to succeed: $result = $var =~ /abc/; If has found this pattern in this string of character, then the returns non-zero value, namely true, does not match returns 0, namely false.! ~ is opposite.

The fifth chapter document read-write

First, opens, the close file

The grammar is open (filevar, filename), filevar is the document handle, or is in the procedure uses for to represent some document the code number, filename is the filename, its way may be the relative way, may also be the absolute way.

open (FILE1, “file1”);
open (FILE1, “/u/jqpublic/file1”);
« 1 2 »