How to Implement front-end and backend connection with perl glue

Source: Internet
Author: User
Tags scalar perl script

1. Perl "glue", which can combine various applications or code in various languages.
Perl can write common scripts, cgi Modules can be used to write Web applications, and DBI can be used to access various databases.
In addition, Perl can stick applications of various levels together to provide more powerful functions.

2.
The front-end is a website Web application. The underlying or backend is written in C, C ++, or Java. Using Perl, you can connect the two to achieve more powerful functions, give full play to their respective advantages.
There are two ways to implement this method in Perl:
1) directly embed code written in other languages in the Perl script. This can use Perl-related modules. Inline is relatively simple, and XS is more powerful but slightly complicated.
2) Another method is to use the Perl system to call the function system:
For example:
Windows

Copy codeThe Code is as follows: use strict;
My $ file = "test.txt ";
System ("edit $ file ");
# Call the dos edit tool
System ("dir ");

.

Another method:
Qx {dir };
To capture the returned results, you can assign the results to a scalar or a list array. If the scalar is used, the final result character is the same. If the array is used, each element corresponds to each row of the result.
For example:

Copy codeThe Code is as follows: use strict;
My @ result = qx {dir };
My $ eachline;
Foreach $ eachline (@ result)
{
Print "$ eachline ";
}

You can also compile your own exe, which is then called by the perl system function (or qx.
For example, you can write an exe program that can be used to input parameters:
Main. c

Copy codeThe Code is as follows: # include <stdio. h>
# Include <stdlib. h>
Int main (int argc, char ** argv)
// Int main (int argc, char * argv [])
{
Int I;
For (I = 0; I <argc; I ++)
{
Printf ("% d arg is % s", I, argv [I]);
}
Return 0;
}
// The main function of the program is to print the parameters passed to the main function.

Example:Copy codeThe Code is as follows :#! /Usr/bin/perl
Use strict;
My @result?qx=main.exe hello iam here };
My $ eachline;
Foreach $ eachline (@ result)
{
Print "$ eachline ";
}

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.