Use Perl here documents to print multiple lines of output
example:
view plain
PERL:
print <<FOO;
Perl offers a convenient way of printing multiple lines of output through an interesting feature known as a "Perl here document".
A multiline Perl here document works like this:
<ol>
<li>The first line of your command will include the two characters <code><<</code> followed by a [...]
先安裝需用到的 module
#ppm-shell
#install DBI
#install DBD-ODBC
view plain
PERL:
#!/usr/bin/perl -w
use strict; # 使用變數前一定要定義
use DBI; # 使用DBI模組, 連結資料庫
use DBD::ODBC;
my $server='localhost\SQLEXPRESS';
my $database="your_db";
my $user="sa";
my $password="123456";
my $DSN = "driver={SQL Server};Server=$server;database=$database;uid=$user;pwd=$password;";
my $dbh = DBI->connect("dbi:ODBC:$DSN", { RaiseError => 1, AutoCommit => 1 }) || die "Can't connect: $DBI::errstr\n";
# 執行 sql 敘述
my $sql_statement = "select * from user_data";
my $sth = $dbh->prepare($sql_statement) || die "Can't prepare the [...]
view plain
PERL:
sub escape {
my($str) = splice(@_);
$str =~ s/(\W)/sprintf('%%%02X', ord($1))/eg;
return $str;
}
sub unescape {
my($str) = splice(@_);
$str =~ s/%(..)/chr(hex($1))/eg;
return $str;
}
http post file upload example
view plain
CODE:
use LWP::UserAgent;
use HTTP::Request::Common;
my $fname1 = "lastUtt.amr";
my $fname2 = "format.txt";
my $url = "http://10.129.6.228/post3.php";
my $ua = LWP::UserAgent->new();
my $req = POST $url, Content_Type => 'form-data',
Content => [
submit => 1,
uploadedfile => [ $fname1 ],
uploadedfile2 => [ $fname2 ]
];
my $response = $ua->request($req);
if ($response->is_success()) {
print "OK: ", $response->content;
} else {
print $response->as_string;
}
VC DLL實作,calling convention 必需是__stdcall
view plain
CODE:
#include <windows.h>
#include <stdio.h>
int __stdcall GetIntFromVC(int x )
{
x *= 2;
return x;
}
int __stdcall GetStrFromVC(char* pbstr, char *lpBuffer)
{
return sprintf(lpBuffer, "*** %s ***", pbstr);
}
避免 name mangling ,加入 .def
view plain
CODE:
LIBRARY test
EXPORTS
GetIntFromVC @1
GetStrFromVC @2
Perl call dll
view plain
CODE:
#! perl -slw
use strict;
use Win32::API;
#傳入一個參數,回傳一個值 ,N: value is a number (long)
my $fun1 = new Win32::API('test.dll', 'GetIntFromVC', [...]