Sharing Perl glue to realize front and rear docking method _perl

Source: Internet
Author: User
Tags scalar perl script

1. Perl "Glue" enables the integration of code in various applications or languages.
Perl can write common scripts, and you can use CGI modules to write Web applications, and you can use DBI to access various databases.
In addition to this, Perl can put together various layers of applications and play more powerful functions.

2.
The front desk is a Web application, the bottom or the background is written in c,c++ or Java, using Perl can connect the two, achieve more powerful features, play their respective advantages.
Perl has two ways to implement this method:
1 directly embedded in the Perl script code written in another language, this can use Perl-related modules, simpler is inline, but slightly more powerful but slightly more complex is XS, etc.
2 The other is using Perl to call function system:
Such as:
Under Windows

Copy Code code as follows:

Use strict;
My $file = "test.txt";
System ("edit $file");
#调用dos的edit工具
System ("dir");

Wait

Another way of writing:
Qx{dir};
Capturing the returned result, you can assign the result to a scalar or an array of lists, and scalar words get the last of the resulting characters; the array words, each of the elements corresponds to each row of the result.
Such as:

Copy Code code as follows:

Use strict;
My @result =qx{dir};
My $eachline;
foreach $eachline (@result)
{
print "$eachline";
}

You can also write your own exe, which is then invoked by the system function (or QX) of Perl.
For example, you can write an EXE program that can give input parameters:
Main.c

Copy Code code 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 out the parameters passed to the main function.

Example:
Copy Code code 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.