Nighthawk Note:
Although Perl has been familiar to the vast majority of programmers over the years, but there's an embarrassing misconception about Perl that Perl is CGI, and it's really a shame that people ask me how Perl and CGI, and PHP, compare to the ASP. Here's a special piece of this digest, may be able to reduce some of these misunderstandings.
This article will further describe Perl's breadth of embeddable technologies and PerlScript's role in scripting technology. The previous article I said Eperl, Embed Perl and Mod_perl Technologies, which are separate areas of technology, are an extension on their own basis. This article will tell you how to write ASP with PerlScript, or write PerlScript in ASP.
After learning this article, you will know how Perl is powerful, and its compatibility is not comparable to any other language. In the current Web page programming, the most prevalent technology: CGI, ASP, PHP, JSP, and so on, which CGI contains Perl, c/S, Java and other technologies, the popular language in cgi technology is Perl,perl's long history, With the traditional programming and natural writing methods, in the ASP, PHP, JSP and other technologies did not appear before, is the web also programming the most popular or standard programming technology. Often someone with Perl or CGI compared to the ASP, PHP, JSP and other technologies, I would like to reiterate here, Perl, CGI and ASP, PHP, JSP is not a domain category, like fruit and sweet potatoes how they compare? These matching methods in the primary school is very detailed, so I hope that the vast number of procedures and technical personnel should not be misled. Perl is a language, and it is a domain with C/s, Java, Basic, and so on, while ASP (Active server page), PHP (Personal home page), JSP (java server page), you can see from English that they have Page behind, simple you can understand to become Hypertext language HTML server-side language, and the true output of HTML is the client language. I write CGI, in particular, a few years of programming in Perl, written countless business software, but now a lot of public opinion on Perl and CGI evaluation is very bad, but these are very irresponsible evaluation of the industry has caused a great loss, seriously slowing the pace of Perl development in the country. perlscript is a scripting language in the Perl language, not a Perl script, which means that Perl is different from what we often say, and it is a scripting language for Perl. Similar to VB, we know that VB has vbscript,perlscript like VBScript, can also be said to be VBScript similar, understand this is good to understand the following content. We know that VBScript is divided into client, server side, the client can be used in browsers (such as: Internet explorer, Netscape), many sites use vbscript do some client analysis and processing work The server side is the same VBScript "<%@ language=" VBScript " %>" that everyone often writes in the ASP. perlscript is a subset of Perl, perL->perlscript.
PerlScript in practical applications there are many places with the usual Perl program is not the same, such as our general display output information are used "print ' info\n\n '", and in the use of PerlScript can not use such a syntax, Otherwise, it will cause the syntax to be unrecognizable; PerlScript is based on object-oriented technology in terms of dictation. So if you want to output information, you must take the object method: "$Response->write (" info ");
How do I use PerlScript as a scripting in a dynamic Service page (ASP)? Usually when we write ASP, we need to declare the language type, for example, we write ASP in VBSCRIPT, we must win the name "<%@ language=" VBSCRIPT "%>", in the use of PerlScript is the same as the declaration format is the same " <%@ language=perlscript%> ". Now we can start writing PerlScript's ASP. Is it a little exciting? We're going to have to write a "Hello World" script by convention. In fact, the ASP can not write what script, can be typed directly in HTML, but now here is to make it easier for you to understand the PerlScript in the specific application of ASP. Now we build the first ASP page
<% @Language =perlscript%>
<HTML>
<TITLE> PerlScript Test </TITLE>
<%
for ($i =0; $i <=10; $i +=2) {
$Response->write ("");
$Response->write ("Hello world!
");
}
%>
</HTML>
Here we must pay attention to
"$Response->write (" ");" Why not print it? Because print is direct to the program, the ASP is the indirect output. Using PerlScript in ASP is an automatic application of ASP-related modules (use ASP;). The content of this page is the size of the output word that loops sequentially.
Access to get the server variable, nor is it what it used to be, the command is
"<%= $Request->servervariables (' Server_software ')->item ()%>"
We're usually in Perl.
"$ENV {' Server_software '};"
Getting the post or get data is much easier than it used to be in a Perl program.
POST: "$Request->form (' name ')->item ()"
and get: "Request->querystring (' name ')->item ()"
In the output of non-"text/html" type data, the first to use the module: "Win32::ole::variant," such as the output "Image/gif" Perl program method is:
print "content-type:image/gif\n\n";
And in PerlScript:
$Response->{contenttype} = "Image/gif";
The output data method is:
$Response->binarywrite (Win32::ole->variant (VT_UI1, $image));
Get an ASP error message:
"$ASPError = $Server->getlasterror ();"
Set Browser cookies: "
$Response->cookies->setproperty (
' Category ',
' Cookies ',
' This is a cookie '
);
"
Set Allow URL: "
$Response->cookies (' Cookie ')->{domain} = ' tanshuai.net ';
"
Set Expiration Time: "
$Response->cookies (' Somecookie ')->{expires} = ' January 1, 2001 ';
"
Database connection: "
<%
#建立连接ADOBD的对象
#
$Conn = $Server->createobject ("ADODB. Connection ");
# output shows each queue name
#
for ($i = 0; $i < $count; $i + +) {
$Response->write ($RS->fields ($i)->name);
$Response->write ("
");
};
# Output All queue values
#
while (! $RS->{eof}) {
for ($i = 0; $i < $count; $i + +) {
$Response->write ("");
$Response->write ($RS->fields ($i)->{value});
$Response->write ("
");
};
#移动到下一个纪录
#
$RS->movenext ();
};
# Close all Objects
#
$RS->close ();
$Conn->close ();
%>
Sub, if, else, else if, for every, while, declaring variables, opening files, character processing, and calling module files in PerlScript are the same as before. Special methods are required only for special processing between Web servers.
In addition, the # is still used as a note symbol at the time of scripting, and it's important to remember that each script command has to be filled with the ";" The closing symbol.
With this article you have mastered how to write an ASP in Perl's Perl script (PerlScript). Perl's power and wide compatibility are not comparable to any other technology. The current Perl embeddable technologies include: C embedded in Perl, Java embedded in Perl, ASP embedded in Perl, Apache embedded in Perl, WSH embedded in Perl, WSC embedded in Perl ...
Perl is actually a simple and easy to learn general information technology language, I think now Universal computer, the first should be popular is the Perl language, Perl more natural than basic. As if people were talking, it was written as if we were dealing with a business. Learn Perl, not only for you to learn other languages (such as: C + +, JAVA) has a lot to promote, help and accelerate the progress of learning, Perl strong development trend, can let you "opportunistic", in other popular programming technology embedded, so that you do not know or find an algorithm is very troublesome, Use Perl to help you get it done quickly. Allowing you to slowly evolve from Perl to that language in other languages is a fairly smooth transition. I've found that learning about Perl has been a lot faster than any other language.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.