免费注册 查看新帖 |

Chinaunix

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

~~遇到一个新问题,各位高手教教我吧!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-12-13 17:40 |只看该作者 |倒序浏览
本帖最后由 花蝴蝶456789 于 2013-12-13 17:43 编辑

{:2_168:} 源代码是这样的数据:
    ##某一行源代码包含了360lx_ ####      <td  class="td_0" align="center" valign="middle" width="12%"><a href='http://university.bailitop.com/Universities-index-id-255.html?360lx_13730' title='http://university.bailitop.com/Universities-index-id-255.html?360lx_13730' target="_blank"><nobr>http://university.bailitop.com/Universities-index-id-255.html?360lx_13730</nobr></a></td>


    ##另一行源代码包含了so.360.cn/或者是www.360.com#####
     <td  class="td_0" align="center" valign="middle" width="12%"><a href='http://so.360.cn/s?ie=utf-8&amp;src=know_side_nlp&amp;q=%E5%89%91%E6%A1%A5%E5%A4%A7%E5%AD%A6&amp;from=know_side_nlp' title='http://so.360.cn/s?ie=utf-8&amp;src=know_side_nlp&amp;q=%E5%89%91%E6%A1%A5%E5%A4%A7%E5%AD%A6&amp;from=know_side_nlp' target="_blank"><nobr>so.360.cn </nobr></a></td>

{:3_201:} 我的程序是这样写的:

@ARGV = <$dir/新建文件夹/*.html>;
open (ORR,">123.txt";

while (<> {
    while中,想生产这样的数据。
    如果某一行包含“360lx_”且相邻的下一行,包含so.360.cn或者是www.360.com。将这两行合并为一行,用制表符分开。且输出至123.txt文件中。
   
}


我的问题描述清楚了吗?请各位高手教教我。非常感谢!!!) )

论坛徽章:
7
戌狗
日期:2013-12-15 20:43:38技术图书徽章
日期:2014-03-05 01:33:12技术图书徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16赛季CBA联赛之青岛
日期:2016-03-17 20:36:13
2 [报告]
发表于 2013-12-14 02:23 |只看该作者
本帖最后由 rubyish 于 2013-12-14 21:26 编辑

biru:
bad:
  1. my $so = qr/(?:so|www).360.c(?:n|om)/;
  2. while (<>) {
  3.     if (/360lx_/) {
  4.         my $next = <>;
  5.         if ( !eof and $next =~ /$so/ ) {
  6.             chomp;
  7.             print "$_\t$next";
  8.         }
  9.     }
  10. }
复制代码
better:
  1. my $so = qr/(?:so|www)\.360\.c(?:n|om)/;
  2. my $before;
  3. while (<>) {
  4.     if ( $before and /$so/ ) {
  5.         chomp $before;
  6.         print "$before\t$_";
  7.         $before = '';
  8.     }
  9.     elsif (/360lx_/) {
  10.         last if eof;
  11.         my $next = <>;
  12.         if ( $next =~ /$so/ ) {
  13.             chomp;
  14.             print "$_\t$next";
  15.         }
  16.         elsif ( $next =~ /360lx_/ ) {
  17.             $before = $next;
  18.         }
  19.     }
  20. }
复制代码

论坛徽章:
0
3 [报告]
发表于 2013-12-14 09:46 |只看该作者
回复 2# rubyish

太厉害了!!非常感谢您!!!{:2_172:}
    谢谢!!

论坛徽章:
7
戌狗
日期:2013-12-15 20:43:38技术图书徽章
日期:2014-03-05 01:33:12技术图书徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16赛季CBA联赛之青岛
日期:2016-03-17 20:36:13
4 [报告]
发表于 2013-12-15 01:23 |只看该作者
回复 3# 花蝴蝶456789
sorry~ 错误~
better
  1. my $so = qr/(?:so|www)\.360\.c(?:n|om)/;
  2. my $before;
  3. while (<>) {
  4.     if ( $before and /$so/ ) {
  5.         chomp $before;
  6.         print "$before\t$_";
  7.         $before = '';
  8.     }
  9.     elsif (/360lx_/) {
  10.         last if eof;
  11.         my $next = <>;
  12.         if ( $next =~ /$so/ ) {
  13.             chomp;
  14.             print "$_\t$next";
  15.         }
  16.         elsif ( $next =~ /360lx_/ ) {
  17.             $before = $next;
  18.         }
  19.     }
  20. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2013-12-23 14:25 |只看该作者
十分感谢。你真好!! {:2_172:}

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP