PerlScript Write ASP

Source: Internet
Author: User
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 ");
#打开系统 DSN
#
$Conn->open ("Tanshuai");

# Execute SQL Query
#
$RS = $Conn->execute ("SELECT * from Orders");

#取得目标查询队列数
$count = $RS->fields->{count};

# 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.


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.