在 2011年1月18日 下午1:51,zero hero <[email protected]>写道:

> use XML::Simple;
> $xml=XMLin("HiBitch.html");
>

xml模块可以解析html吗? html有些时候是不许要结束标签的,这种情况下XML可能就吃力了吧。


> 在 2011年1月18日 下午1:30,cnhack TNT <[email protected]>写道:
>
>
>>
>> 2011/1/18 Kermit Mei <[email protected]>
>>
>>
>>>
>>> 在 2011年1月17日 下午6:25,cnhack TNT <[email protected]>写道:
>>>
>>>
>>>> use Data::Dumper;
>>>>
>>>> $s = q/<button type="button" style = "
>>>> border:none;background:url(button_bk.png); width:150px; height:49px; ">/;
>>>>
>>>> ($c) = $s =~ /<([^<>]+?=[^<>]+?)>/;
>>>>
>>>> 这个可以,但是为什么我写的这个不能匹配:
>>> ($c) = $s =~ /<\w+\s*(\w+\s*=\s*\w+\s*)>/;
>>>
>>
>>
>> 因为 \w 只包括 [a-zA-Z0-9_]
>>
>>
>>
>>>
>>>
>>>>  $bth{$1} = $2 while $c =~ /\s([\w-]+)\s*=\s*"([^""]+?)"/g;
>>>>
>>>> print Dumper \%bth;
>>>>
>>>>
>>>
>>> 恩,多谢,修改一下就可以用了(要替换的话不知有没有办法可以不生成那俩变量?):
>>> while ($c =~ /\s([\w-]+)\s*=\s*"([^""]+?)"/g) {
>>>     my $tmp1 = $1;
>>>     my $tmp2 = $2;
>>>
>>>     $tmp2 =~ s/\s//g;
>>>     $bth{$tmp1} = $tmp2;
>>> }
>>>
>>>
>>
>> 正则匹配出来的反引用变量只读,你后面进行了 s// 操作,所以还是需要将反引用变量先赋值给另外的变量的。 不建议简单 s/\s//g,
>> 因为有些属性可能是这样的 class="class1 class2", 你删掉空白字符就悲催了,你可以 s/^\s*|\s*$//g;
>> 删掉头尾空白字符。
>>
>>
>>>
>>>   --
>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
>> 要取消订阅此网上论坛,请发送电子邮件至 
>> [email protected]<perlchina%[email protected]>
>> 。
>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>>
>
>
>
> --
> Salt Fish Ready To Turn Over!~~~
>
>
>  --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> 要取消订阅此网上论坛,请发送电子邮件至 
> [email protected]<perlchina%[email protected]>
> 。
> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>



-- 
B.R
Kermit

-- 
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。

回复