|
OnOverflow
Method OnOverflow is caused each time when there is a filter which values of counters have exceeded one of the specified borders of the signal system (see method StopOn). You can redefine this method in a derivative class, or simply block existing method CTT:: OnOverflow as it is made in an example.
Plans
* Procedures of testing
* The POD-documentation
Perl'? For the web designer
To solve the primary goals facing to the web designer, without necessity of multimonthly studying programming languages, we shall lower{omit} long training the theory and at once we shall pass to practice. We shall study during creation of scripts which you can test on the site.
That it is necessary to know about the server
Before to write CGI-scripts, it is necessary to learn{find out} some information on the server on which these scripts will work. All this information can be received from the provider where there is a site. The free-of-charge services giving a place under pages, usually place such information in "helps", in the sections devoted CGI, etc. Addresses of servers which resolve performance of CGI-scripts, we published in last number{room} MK.
The most important parameter of that it is necessary to know - a way to interpreter Perl on the server which it is necessary to specify in the first line of each program written on Perl. Usually she looks like:
*!/usr/bin/perl
We shall use such line in the further examples.
It is still necessary to know a full way to cgi-bin-direktorii your site and a full way to his{its} basic (root) directory. It not the address beginning with http:// is a full way from root directory of the server on which there is your site, and looking like:
/home2/your_domen/public_html/
That the script had an opportunity to send letters, it is required to learn{find out} a way to a mailer (sendmail). He can look approximately so:
/usr/sbin/sendmail
Tools
For a spelling of scripts on Perl'?, it is not necessary to establish any special software - any text editor, the same "Notebook" included Windows will approach also. But all the same upomjanu a pair of tools which will help to simplify a spelling and debugging of scripts. First of all, interpreter Perl for Windows which can be loaded from page http://www.activestate.com/ActivePerl/download.htm (or to choose other variants of addresses from the server http://www.perl.com/) is required. And for programming and debugging the tool most convenient, in my opinion, is Perl Builder (http://www.solutionsoft.com/). Except for step-by-step debugging with an opportunity of viewing on a course of values of variables, there is a function of automatic generation of some scripts. And in general, there is a lot of a various software which helps in creation and debugging of programs on Perl - we it is necessary with it{him} we shall familiarize further.
That I have described these tools right now and I shall mention from time to time them in clause{article}, does not mean, that they are obligatory. You can easy type{collect} all examples in the Notebook, is simple then you cannot make debugging of scripts during their spelling is will be come to do{make} directly on the server.
We create the counter of visitings
There is a set of the ratings giving counters poseshenij, collecting statistics. In exchange they demand to establish at you on a site the button. But what to do{make}, if you do not pursue high position in a rating and do not wish to insert into the page the button of a rating? You need to count visitors and to collect some statistics. Or why to not check correctness of the information collected by the another's counter? And can, you want to create own rating? OK, let's make all over again the elementary counter, and then we shall transform it{him} into system of gathering of statistics and convenient viewing of the collected information. And at the same time also we shall learn to generate a picture of the counter.
Let's start with the elementary text counter. To tell the truth, that he worked, support by the server of instructions SSI (Server Side Includes) is necessary - about it also learn{find out} from the hosting - provider.
Create in the text editor two files and save them on the disk with names count.cgi and count.txt accordingly. Second of them let will be empty, and in the first type{collect} the following text:
*!/usr/bin/perl
$namefile = "count.txt";
open (COUNTFILE, "$namefile");
$count = <COUNTFILE>;
close (COUNTFILE);
chomp ($count);
$count = $ count + 1;
open (COUNTFILE, "> $namefile ");
print COUNTFILE "$count";
close (COUNTFILE);
print " Content-Type: text/html ";
print "$count";
exit;
If you typed{collected} the text in Perl Builder, that, having chosen in menu Run/Debug> Check Syntax With-w Flag, can check up at once a script on presence of mistakes. If mistakes are present - that Perl Builder will give out corresponding messages with number{room} of a line which contains a mistake.
Now with the help of the FTP-client copy both files in cgi-bin-direktoriju the server. We shall note what to do{make} it it is necessary in mode ASCII. After that establish access rights (CHMOD command) for count.cgi - 755, and for count.txt - 666. It are necessary to insert a call of a script into HTML-page. In that place of page where you want to see the counter of visitings insert a line:
<! - *exec cgi = "/cgi-bin/count.cgi "->
Where/cgi-bin/count.cgi - a full way to a file of a script from root directory of your site. T. e. If the full way to a script looks as http://your-domen.com/cgi-bin/count.cgi in a call of a script we write/cgi-bin/count.cgi.
Now it is possible to load page on the server and to open her{it} in a browser. You will see figures - the indications of the counter increasing by each call of page. It are necessary to understand, that we such have made.
That you though could understand a little, about what there is a speech, offer some initial data on that, " that is that in Perl ".
Names of scalar variables always begin with a sign "$". For example: $ind. Scalar variable is the variable containing only one value. As against a file (list) which contains set of values. The name of a file always begins with a sign. For example: @ind.
So, that the first line of a script specifies where to search for interpreter Perl, you already know.
Line:
$namefile="count.txt ";
Places in a variable $namefile a name of a file count.txt;
open (COUNTFILE, "$namefile");
Opens a file count.txt for reading, connecting the name of a file with descriptor COUNTFILE;
$count = <COUNTFILE>;
Reads out from a file last value of the counter. As for the first time to read out there is nothing, in a variable $count value "0" will appear;
close (COUNTFILE);
Closes a file;
chomp ($count);
If at the end of the read out line there is a symbol of translation of a line (in Perl looks like " ") - he will be removed. In our case of such symbol no. But it is better to be reinsured, than then to search for not clear mistakes.
$count = $ count + 1;
We increase value of the counter by unit. This operation can be written down also so:
$count ++;
But for presentation we shall use the previous variant.
open (COUNTFILE, "> $namefile ");
Let's open a file count.cgi for recording, having destroyed (a symbol ">") his{its} contents
print COUNTFILE "$count";
Let's write down in a file new value of the counter
close (COUNTFILE);
Let's close a file
print " Content-Type: text/html ";
print "$count";
We pass new value of the counter as result of job of a script that the server has switched on this value in structure of HTML-page - in that place where there is a line <! - *exec cgi = "/cgi-bin/count.cgi "->
exit;
The end of performance of the program (it is possible to do without it but why to not follow traditions).

|