汇率.pl
第二行的
$rcd="D:/记录/汇率记录.txt";
指定了一个用于记录汇率的文本,每次打开除了显示汇率还会往文本追加查询结果,供以后观察。
你知道,我perl很菜,为达目的,不仅生成临时文件,还用了wget。
求助啊 为什么发上来 $& 会变成 [ DISCUZ_CODE_0 ] (在code里面)
改为quote存放代码,使用IE浏览器的可以通过 CTRL+鼠标左键点击quote框框, 选中框中的代码
$html="http://www.baidu.com/s?wd=美元汇率";
$rcd="E:/R_记录/汇率记录.txt";
open WRITE,">>$rcd" or warn "$!";
system("wget -O main.txt $html 2>nul >nul");
open READ,"<main.txt" or warn "File not exists\n";
foreach (<READ>) {
if (/(1美元=.*人民币元)/) {
print "$&\n";
print WRITE "$& ";
if (/汇率数据由和讯外汇提供,更新时间:(\d+)-(\d+)-(\d+)/) {
print "$&\n\n";
print WRITE "${1}-${2}-${3}\n";
}
}
}
close WRITE;
$html="http://www.baidu.com/s?wd=汇率";
system("wget -O main.txt $html 2>nul >nul");
open READ,"<main.txt" or warn "File not exists\n";
foreach (<READ>) {
if (/(更新时间.*\d:\d+)/) {
print "$&\n";
foreach $a (0..5) {
if ($_=~s#.*?<th.*?>(.*?)</th>##i) {
$arr1[$a]=$1;
}
}
foreach $a (0..5) {
if ($_=~s#.*?<td.*?>(.*?)</td>##i) {
printf "%-10s \t\t%s\n",$arr1[$a],$1;
}
}
}
}
print "Press Enter to quit";
<STDIN>;
人性化输出 | 1美元=6.4845人民币元 | | 汇率数据由和讯外汇提供,更新时间:2011-06-02 | | | | 更新时间:2011-6-2 10:31:17 | | 币种 美元(USD) | | 交易单位 100 | | 中间价 648.34 | | 现汇买入价 647.04 | | 现钞买入价 641.86 | | 卖出价 649.64 | | Press Enter to quitCOPY |
[ DISCUZ_CODE_1 ]COPY
|