EvoTalk

Archive for the ‘Perl’ Category

13 十月, 2009

Perl Here Document

Posted by: asd In: Code Snippet| Perl| 程式設計

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>&lt;&lt;</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-&gt;connect("dbi:ODBC:$DSN", { RaiseError =&gt; 1, AutoCommit =&gt; 1 }) || die "Can't connect: $DBI::errstr\n";

 

# 執行 sql 敘述

my $sql_statement = "select * from user_data";

my $sth = $dbh-&gt;prepare($sql_statement) || die "Can't prepare the [...]

Tags:

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;

}

19 二月, 2009

Http Post using Perl

Posted by: asd In: Code Snippet| Perl| 程式設計

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-&gt;new();

my $req = POST $url, Content_Type =&gt; 'form-data',

 Content      =&gt; [

  submit =&gt; 1,

  uploadedfile =&gt;  [ $fname1 ],

  uploadedfile2 =&gt; [ $fname2 ]

 ];

my $response = $ua-&gt;request($req);

 

if ($response-&gt;is_success()) {

    print "OK: ", $response-&gt;content;

} else {

    print $response-&gt;as_string;

}

Tags: ,

20 一月, 2009

Perl Call VC Dll

Posted by: asd In: Code Snippet| Perl| 程式設計

VC DLL實作,calling convention 必需是__stdcall
view plain

CODE:

#include &lt;windows.h&gt;

#include &lt;stdio.h&gt;

 

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', [...]

Tags: ,


  • BK: 大於和小於在今日更廣泛地使用於標籤上,故在此補充該英文用法: : angle bracket []: square bracket
  • luh1688: 非常實用且謝謝!~
  • asd: 好的,不過很久沒修改了,不知道能不能動 寄到您的yahoo信箱
  • LIANG: nice post, thank you
  • Justmaker: 您好,請問可以跟你要source嗎?我最近有在看股票,想要enhance您的小工具,不知是否可以開放?

Category

Page 1 of 612345»...Last »