以後可以不用靠 excel 連了 ya~
安裝步驟
下載並安裝 ActivePerl
打開命令提示字元 輸入
ppm repo add bribes (如果是Perl 5.10以上,請參考Bribe的教學)
ppm install Win32-DDE
即可使用
簡單Perl範例
use strict;
use warnings;
use Win32::DDE::Client;
use Win32::DDE;
my $DDEServer = 'XQFAP';
my $DDEHost = 'Quote';
my @Stocks = ( "2330.TW", "2498.TW", "2454.TW", "2317.TW" );
my $Client = new Win32::DDE::Client ($DDEServer, $DDEHost);
if ($Client->Error == Win32::DDE::DMLERR_NO_CONV_ESTABLISHED) {
die "Hey! start the silly DDE server!\nError=[" .
Win32::DDE::ErrorText ($Client->Error) . "]";
}
sub query {
my $v = $Client->Request( $_[0] );
defined $v or die "DDE request '$_[0]' failed";
$v;
}
sub header { "ID\tName\tPrice\tTotalVolume\n" }
sub name { $_[0] . '-' . 'Name'; }
sub price { $_[0] . '-' . 'Price'; }
sub total_vol { $_[0] . '-' . 'TotalVolume'; }
print &header;
foreach my $i (@Stocks) {
print $i .
"\t" . &query(&name($i)) .
"\t" . &query(&price($i)) .
"\t" . (int &query(&total_vol($i))) .
"\n";
}
use warnings;
use Win32::DDE::Client;
use Win32::DDE;
my $DDEServer = 'XQFAP';
my $DDEHost = 'Quote';
my @Stocks = ( "2330.TW", "2498.TW", "2454.TW", "2317.TW" );
my $Client = new Win32::DDE::Client ($DDEServer, $DDEHost);
if ($Client->Error == Win32::DDE::DMLERR_NO_CONV_ESTABLISHED) {
die "Hey! start the silly DDE server!\nError=[" .
Win32::DDE::ErrorText ($Client->Error) . "]";
}
sub query {
my $v = $Client->Request( $_[0] );
defined $v or die "DDE request '$_[0]' failed";
$v;
}
sub header { "ID\tName\tPrice\tTotalVolume\n" }
sub name { $_[0] . '-' . 'Name'; }
sub price { $_[0] . '-' . 'Price'; }
sub total_vol { $_[0] . '-' . 'TotalVolume'; }
print &header;
foreach my $i (@Stocks) {
print $i .
"\t" . &query(&name($i)) .
"\t" . &query(&price($i)) .
"\t" . (int &query(&total_vol($i))) .
"\n";
}
沒有留言:
張貼留言