免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1849 | 回复: 5
打印 上一主题 下一主题

一个关于字符串匹配的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-10 10:51 |只看该作者 |倒序浏览
我想从一个网页文件中找到这个字符串,然后从中分别取出32和23
<p>High: 32° Low: 23°</p>


这样写哪里错了呢?

`wget -O - http://weather.yahoo.com/forecast/CHXX0008_c.html > $file`;
open(FILE, $file) or die "Could not open file $file: $!\n";

$leadspace="  "; #spacing before each high low

$trailspace="   "; #spacing after each high low.

$degree=" ℃"; #give me the degree symbol, not everyone has same locale


while(<FILE>){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#get the high temp

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(my $high) = /<p>High: (-?\d+)#176; Low: \-?\d+#176;<\/p>/;


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#get the low temp

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(my $low) = /<p>High: \-?\d+#176; Low: (-?\d+)#176;<\/p>/;


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#print the high and low temp for the specified day

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($high=~/\d+/ && $low=~/\d+/ && ++$count<=$day){print "$leadspace$high$degree/$low$degree$trailspace";}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif($count>=$day){print "\n"; exit;} #don't keep looking if everything has been found

}

论坛徽章:
0
2 [报告]
发表于 2008-07-10 10:54 |只看该作者
晕。。找到原因了,是我马虎了。。。

另外,怎么输出摄氏度的符号?到桌面上之后输出的是乱码(图的右下角位置)



[ 本帖最后由 kimux 于 2008-7-10 11:04 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2008-07-10 10:57 |只看该作者
原帖由 kimux 于 2008-7-10 10:54 发表
晕。。找到原因了,是我马虎了。。。

另外,怎么输出摄氏度的符号?我这里输出的是乱码


将符号复制到程序中就可以了吧

论坛徽章:
0
4 [报告]
发表于 2008-07-10 10:59 |只看该作者
另外,你的high和low可以放在一个正则表达式中求,分别为$1和$2

论坛徽章:
0
5 [报告]
发表于 2008-07-10 11:12 |只看该作者
说实话。。我对Perl并不了解。。

这个天气预报脚本是在网上找的

不过他天气显示的有问题,我就自己改一下。。。能用就行了,HEHE

论坛徽章:
0
6 [报告]
发表于 2008-07-10 11:16 |只看该作者
对了,原来的脚本里他是这样显示符号的

$degree= encode_utf8( "\x{00B0}" );


只不过显示出来的不是摄氏度。。我也不知道是什么符号
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP