原文:http://myblog.acrehr.com/?p=116 今天google和baidu了一整天,终于把"读写股票文件"搞了出来. 原理:读写二进制文件(都是用unpack的函数), 我们以后就可以用它读股票文件,读数据模拟股票操作, 股票文件是大智慧股票软件下的日线格式, 测试系统环境:windows2000和FreeBSD 6.2下通过 .
perl例子的代码 ——————————————————— $time1 = time(); open(MYFILE,”500001.day”) or die (”cannot open input file file1\n”);
#binmode(MYFILE); my $buff; #my $i=1; while(read(MYFILE, $buff, 40)) { # $. ,$_ 为内置变量 # $. 为行号 # $_ 行的内容,以回车结尾 # chomp 去除回车 #chomp; #($a1, $a2, $a3, $a4, $a5, $a6, $a7) = unpack(”H8 H8 H8 H8 H8 H8 H8″, $buff); ($a1, $a2, $a3, $a4, $a5, $a6, $a7) = unpack(”i i i i i i i”, $buff); print “=>”.$a1.”\n”; print “=>”.$a2.”\n”; print “=>”.$a3.”\n”; print “=>”.$a4.”\n”; print “=>”.$a5.”\n”; print “=>”.$a6.”\n”; print “=>”.$a7.”\n”; print “***********************\n”; #if($i==5){ last;} #$i++; }
close(MYFILE); $time2 = time(); print $time2 - $time1;
另外:下载股票文件: 500001.day |