PerlScript compiling ASP

Source: Internet
Author: User
Tags perl script

Note:
Although Perl has been familiar to many programmers over the past few years, there is an embarrassing misunderstanding about Perl. I think Perl is CGI. Some people often ask me about Perl, CGI, and PHP, it is a pity to compare it with ASP. the following abstract is specially posted here, which may reduce some misunderstandings in this regard.

This article will further introduce Perl's wide range of embedding technologies and PerlScript's functions in the field of script technology. In previous articles, I mentioned ePerl, Embed Perl, and Mod_Perl technologies. They are all independent fields and are extensions based on their own. This article describes how to use PerlScript to write ASP or PerlScript in ASP.

After learning this article, you will know how powerful Perl is and its compatibility is comparable to that in no language. Currently, most popular Web page programming technologies include CGI, ASP, PHP, and JSP. CGI includes Perl, C/C ++, JAVA, and other technologies, the popular language in CGI technology is Perl, which has a long history and has a traditional programming method and natural programming method. Before ASP, PHP, JSP and other technologies appeared, it is the most popular or standard programming technology in WEB programming. Some people often compare Perl or CGI with ASP, PHP, JSP, and other technologies. Here I want to reiterate that Perl, CGI and ASP, PHP, and JSP are not in the same field, just like how do they compare fruits with sweet potatoes? These ratio methods are described in detail in primary school, so we hope that the majority of program technicians will not be misled. Perl is a language. It is in a category and field with C/C ++, Java, Basic, etc. ASP (Active Server Page), PHP (Personal Home Page) JSP (Java Server Page), you can see from English that they are followed by pages, simple you can understand as hypertext Language HTML Server language, the real output HTML is the client language. I have compiled CGI programs, especially programs that have been written in Perl for several years, and have written countless commercial software. However, many public opinions are not very good at Perl and CGI, however, these are very irresponsible comments, which have brought great losses to this industry and severely slowed down the development of Perl in China. PerlScript is a scripting language in Perl. It is not a Perl script. In other words, we often say that Perl is different. It is a scripting language of Perl. Similar to VB, we know that VB has VBScript, and PerlScript is like VBScript. It can also be said that it is similar to VBScript. To understand this, you just need to understand the following content. As you know, VBScript is divided into clients and servers. Clients can be applied in browsers (such as Internet Explorer and Netscape). Many websites use VBScript to analyze and process clients; the server is the same as VBScript that is frequently written in ASP. "<% @ LANGUAGE =" VBSCRIPT "%> ". PerlScript is a subset of Perl, Perl-> PerlScript.

PerlScript is different from the Perl program that is usually written in many places in actual applications. For example, the output information is usually "print 'info \ n \ n ';", this syntax cannot be used when PerlScript is used. Otherwise, the syntax cannot be identified. PerlScript uses the object-oriented technology as the basis for silent writing. Therefore, to output information, you must use the object method: "$ Response-> Write (" info ");".

On the Dynamic service page, how does one use PerlScript as a script? We usually need to declare the LANGUAGE type when writing ASP. For example, when we use VBScript to write ASP, we must win the name "<% @ LANGUAGE =" VBSCRIPT "%> ", the same is true when PerlScript is used. The declaration format is the same: "<% @ Language = PerlScript %> ". Now we can start to write ASP for PerlScript. Are you a little excited? By convention, we have to write a "hello world" script. In fact, ASP does not need to write any scripts and can be directly played in HTML. However, this is to make it easier for you to understand the specific application of PerlScript in ASP. Now we create 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>
You must note that
"$ Response-> Write (" ");" why not use print? Because print is direct for programs, and ASP is indirect output. Using PerlScript in ASP automatically applies ASP-related modules (use ASP ;). The content of this page is the size of output words cyclically and sequentially.

Access the server variable, which is not the same as before. The command is
"<% = $ Request-> ServerVariables ('server _ soft')-> Item () %>"

In Perl
"$ ENV {'server _ soft '};"
It is much easier to get post or GET data than in Perl programs.
POST: "$ Request-> Form ('name')-> Item ()"
GET: "Request-> QueryString ('name')-> Item ()"

When outputting non-"text/html" data, you must first use the module: "Win32: OLE: Variant ;", for example, the method for outputting the "image/GIF" Perl program is:
Print "Content-type: image/GIF \ n ";
In PerlScript:
$ Response-> {ContentType} = "image/GIF ";

The data output method is:
$ Response-> BinaryWrite (Win32: OLE-> Variant (VT_UI1, $ image ));
Obtain the ASP error message:
"$ ASPError = $ Server-> GetLastError ();"
Set browser Cookies :"
$ Response-> Cookies-> SetProperty (
'Category ',
'Cookies ',
'This is a cookie'
);
"
Set the allowed URL :"
$ Response-> Cookies ('cookies')-> {Domain} = 'tanshuai. net ';
"
Set expiration time :"
$ Response-> Cookies ('somecookies')-> {Expires} = 'january 1, 123 ';
"
Database Connection :"
<%
# Create an object connecting to ADOBD
#
$ Conn = $ Server-> CreateObject ("ADODB. Connection ");

# Enable system DSN
#
$ Conn-> Open ("Tanshuai ");

# Execute an SQL query
#
$ RS = $ Conn-> Execute ("SELECT * FROM Orders ");

# Retrieve the number of target query queues
$ Count = $ RS-> Fields-> {Count };

# Each queue name is displayed in the output.
#
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 ("
");
};

# Move to the next record
#
$ RS-> MoveNext ();
};

# Close all objects
#
$ RS-> Close ();
$ Conn-> Close ();
%>

In PerlScript, sub, if, else, else if, for each, while, declare variables, open files, process characters, and call module files are all in the same way as before. Only special methods are needed for special processing between Web servers.

# It is still used as an annotation symbol when writing a script, and you must remember to enter the ";" End symbol after each script command ends.

Through this article, you have learned how to use Perl's Perl script (PerlScript) to write ASP. The powerful functions and extensive compatibility of Perl do not have any comparable technology. Currently, Perl embedding technology includes: C embedding Perl, Java Embedding Perl, ASP embedding Perl, Apache embedding Perl, WSH embedding Perl, and WSC embedding Perl ......

Perl is actually a simple and easy-to-learn general information technology language. I think the first thing that should be popularized for computers is the Perl language. PERL is much more natural than BASIC. As if people are talking, it is written in the same way as we are dealing with transactions. Learning Perl not only greatly promotes your learning of other languages (such as C/C ++ and JAVA), but also helps you speed up your learning progress. The powerful development trend of Perl is as follows, it allows you to "opportunistic" and embed it in other popular programming technologies, so that you can use Perl to help you quickly complete it when you do not know or feel that an algorithm is troublesome. It is a smooth and smooth transition from Perl to Perl in other languages. After learning Perl, I found that the speed of learning other languages is greatly improved.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.