From freeespeech at gmail.com Tue Mar 3 07:25:28 2009 From: freeespeech at gmail.com (owen nirvana) Date: Tue, 3 Mar 2009 23:25:28 +0800 Subject: [PerlChina] China-pm Digest, Vol 43, Issue 23 In-Reply-To: References: Message-ID: > my ($name, $title); > while (<>){ > if (/^(\d+)\s+(.*)$) { > if ($name) { > // 保存上一个 save $name, $title > // 下面开始处理一个新的 > $name = ''; > $title = ''; > } > $name = $1; > $title .= $2; > } elsif(/^\s+(.*)$/) { > $title .= $1; > } > // save last one 把自己的老问题翻上来,今天突然发现如果不是elsif, 而是else, 就只有匹配行的第二行会被合并,下一行就不会, why gtalk:freeespeech at gmail.com 2008/11/18 : > Send China-pm mailing list submissions to > china-pm at pm.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.pm.org/mailman/listinfo/china-pm > or, via email, send a message with subject or body 'help' to > china-pm-request at pm.org > > You can reach the person managing the list at > china-pm-owner at pm.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of China-pm digest..." > > > Today's Topics: > > 1. Re: China-pm Digest, Vol 43, Issue 21 (truncatei) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 17 Nov 2008 22:01:40 +0800 > From: truncatei > Subject: Re: [PerlChina] China-pm Digest, Vol 43, Issue 21 > To: china-pm at pm.org > Message-ID: > > Content-Type: text/plain; charset="utf-8" > > 2008/11/17 owen nirvana > >> 谢谢,问题是归到上一行这样的操作,我不知道如何用正则表达式完成,那不等于是让表达式再回溯吗 >> gtalk:freeespeech at gmail.com >> >> >> >> >> >> >> >> 还有一个问题,是关于提取数据的 >> >> >> >> 2222 eewweasdds,asdasd.sadsadasdas >> >> ddasdddddddddddddddddddda >> >> ddddddddddddddddddddddddddd >> >> 2821 easdddddddddddddddddddddddd >> >> 2192 288888888888888888888ass0a-das. >> >> as;dddsaddaa0---------22222222 >> >> >> >> 诸如此类,左边很好办,可是右边并不限于单行,我该如何把这样的数据提取为 name title的格式存到数据表里呢 >> >> > > > > my ($name, $title); > while (<>){ > if (/^(\d+)\s+(.*)$) { > if ($name) { > // 保存上一个 save $name, $title > // 下面开始处理一个新的 > $name = ''; > $title = ''; > } > $name = $1; > $title .= $2; > } elsif(/^\s+(.*)$/) { > $title .= $1; > } > // save last one > > 好久不写了,上面的代码或许会有些错误,大概的流程整理出来了: > 每次遇到数字就开始一条数据,否则视为向当前数据中添加title > > > -- > "老是呆在那里不好,我们随生活需要四处迁徙,多年以来的梦想,至今还未实现,压力堵塞了我们的耳朵,工作生涯到了尽头,还是一无所有,我们应该给后人留下点儿什么,教训是不会刻在纪念碑上的,光荣的命令和指引之手,也可请求,简单地改变一下角度就足够了" > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > _______________________________________________ > China-pm mailing list > China-pm at pm.org > http://mail.pm.org/mailman/listinfo/china-pm > > End of China-pm Digest, Vol 43, Issue 23 > **************************************** > From cnhacktnt at gmail.com Tue Mar 3 19:10:25 2009 From: cnhacktnt at gmail.com (cnhack TNT) Date: Wed, 4 Mar 2009 11:10:25 +0800 Subject: [PerlChina] China-pm Digest, Vol 43, Issue 23 In-Reply-To: References: Message-ID: 用 else 的话, 你得把 /^\s+(.*)$/ 放在 else 块中,再做处理: 我是这样处理的: ------------------------------------------------- #!/usr/bin/perl; use strict; my ($name, $title) = (); while(){ if (/^(\d+)\s+(.*)$/){ print "====\n$name\t$title\n=====\n" if $name; $name = $1; $title = $2; next; } elsif (/^\s+(.*)$/) { $title.= $1; } print "====\n$name\t$title\n=====\n" if eof; } __DATA__ 2222 eewweasdds,asdasd.sadsadasdas ddasdddddddddddddddddddda ddddddddddddddddddddddddddd 2821 easdddddddddddddddddddddddd 2192 288888888888888888888ass0a-das. as;dddsaddaa0---------22222222 3030 123456 789 #-----------------END----------------- 2009/3/3 owen nirvana > > my ($name, $title); > > while (<>){ > > if (/^(\d+)\s+(.*)$) { > > if ($name) { > > // 保存上一个 save $name, $title > > // 下面开始处理一个新的 > > $name = ''; > > $title = ''; > > } > > $name = $1; > > $title .= $2; > > } elsif(/^\s+(.*)$/) { > > $title .= $1; > > } > > // save last one > > 把自己的老问题翻上来,今天突然发现如果不是elsif, 而是else, 就只有匹配行的第二行会被合并,下一行就不会, why > gtalk:freeespeech at gmail.com > > > > 2008/11/18 : > > Send China-pm mailing list submissions to > > china-pm at pm.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > http://mail.pm.org/mailman/listinfo/china-pm > > or, via email, send a message with subject or body 'help' to > > china-pm-request at pm.org > > > > You can reach the person managing the list at > > china-pm-owner at pm.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of China-pm digest..." > > > > > > Today's Topics: > > > > 1. Re: China-pm Digest, Vol 43, Issue 21 (truncatei) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Mon, 17 Nov 2008 22:01:40 +0800 > > From: truncatei > > Subject: Re: [PerlChina] China-pm Digest, Vol 43, Issue 21 > > To: china-pm at pm.org > > Message-ID: > > > > Content-Type: text/plain; charset="utf-8" > > > > 2008/11/17 owen nirvana > > > >> 谢谢,问题是归到上一行这样的操作,我不知道如何用正则表达式完成,那不等于是让表达式再回溯吗 > >> gtalk:freeespeech at gmail.com < > gtalk%3Afreeespeech at gmail.com > > >> > >> > >> >> > >> >> > >> >> 还有一个问题,是关于提取数据的 > >> >> > >> >> 2222 eewweasdds,asdasd.sadsadasdas > >> >> ddasdddddddddddddddddddda > >> >> ddddddddddddddddddddddddddd > >> >> 2821 easdddddddddddddddddddddddd > >> >> 2192 288888888888888888888ass0a-das. > >> >> as;dddsaddaa0---------22222222 > >> >> > >> >> 诸如此类,左边很好办,可是右边并不限于单行,我该如何把这样的数据提取为 name title的格式存到数据表里呢 > >> > >> > > > > > > > > my ($name, $title); > > while (<>){ > > if (/^(\d+)\s+(.*)$) { > > if ($name) { > > // 保存上一个 save $name, $title > > // 下面开始处理一个新的 > > $name = ''; > > $title = ''; > > } > > $name = $1; > > $title .= $2; > > } elsif(/^\s+(.*)$/) { > > $title .= $1; > > } > > // save last one > > > > 好久不写了,上面的代码或许会有些错误,大概的流程整理出来了: > > 每次遇到数字就开始一条数据,否则视为向当前数据中添加title > > > > > > -- > > > "老是呆在那里不好,我们随生活需要四处迁徙,多年以来的梦想,至今还未实现,压力堵塞了我们的耳朵,工作生涯到了尽头,还是一无所有,我们应该给后人留下点儿什么,教训是不会刻在纪念碑上的,光荣的命令和指引之手,也可请求,简单地改变一下角度就足够了" > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > http://mail.pm.org/pipermail/china-pm/attachments/20081117/e8fdbb3d/attachment-0001.html > > > > > > ------------------------------ > > > > _______________________________________________ > > China-pm mailing list > > China-pm at pm.org > > http://mail.pm.org/mailman/listinfo/china-pm > > > > End of China-pm Digest, Vol 43, Issue 23 > > **************************************** > > > _______________________________________________ > China-pm mailing list > China-pm at pm.org > http://mail.pm.org/mailman/listinfo/china-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From freeespeech at gmail.com Sun Mar 8 00:23:42 2009 From: freeespeech at gmail.com (owen nirvana) Date: Sun, 8 Mar 2009 16:23:42 +0800 Subject: [PerlChina] China-pm Digest, Vol 46, Issue 2 In-Reply-To: References: Message-ID: 阁下也还是elsif啊,我的问题是,既然只有两种可能,那么不应该需要elsif,匹配到第一条分支,否则进入第二条,不应该有第三种可能, gtalk:freeespeech at gmail.com 2009/3/5 : > Send China-pm mailing list submissions to > china-pm at pm.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.pm.org/mailman/listinfo/china-pm > or, via email, send a message with subject or body 'help' to > china-pm-request at pm.org > > You can reach the person managing the list at > china-pm-owner at pm.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of China-pm digest..." > > > Today's Topics: > > 1. Re: China-pm Digest, Vol 43, Issue 23 (cnhack TNT) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 4 Mar 2009 11:10:25 +0800 > From: cnhack TNT > Subject: Re: [PerlChina] China-pm Digest, Vol 43, Issue 23 > To: china-pm at pm.org > Message-ID: > > Content-Type: text/plain; charset="gb2312" > > 用 else 的话, 你得把 /^\s+(.*)$/ 放在 else 块中,再做处理: > 我是这样处理的: > ------------------------------------------------- > #!/usr/bin/perl; > use strict; > > my ($name, $title) = (); > > while(){ > > if (/^(\d+)\s+(.*)$/){ > > print "====\n$name\t$title\n=====\n" if $name; > $name = $1; > $title = $2; > next; > > } elsif (/^\s+(.*)$/) { > > $title.= $1; > } > > print "====\n$name\t$title\n=====\n" if eof; > > } > > > __DATA__ > 2222 eewweasdds,asdasd.sadsadasdas > ddasdddddddddddddddddddda > ddddddddddddddddddddddddddd > 2821 easdddddddddddddddddddddddd > 2192 288888888888888888888ass0a-das. > as;dddsaddaa0---------22222222 > 3030 123456 > 789 > > #-----------------END----------------- > > 2009/3/3 owen nirvana > >> > my ($name, $title); >> > while (<>){ >> > if (/^(\d+)\s+(.*)$) { >> > if ($name) { >> > // 保存上一个 save $name, $title >> > // 下面开始处理一个新的 >> > $name = ''; >> > $title = ''; >> > } >> > $name = $1; >> > $title .= $2; >> > } elsif(/^\s+(.*)$/) { >> > $title .= $1; >> > } >> > // save last one >> >> 把自己的老问题翻上来,今天突然发现如果不是elsif, 而是else, 就只有匹配行的第二行会被合并,下一行就不会, why >> gtalk:freeespeech at gmail.com >> >> >> >> 2008/11/18 : >> > Send China-pm mailing list submissions to >> > china-pm at pm.org >> > >> > To subscribe or unsubscribe via the World Wide Web, visit >> > http://mail.pm.org/mailman/listinfo/china-pm >> > or, via email, send a message with subject or body 'help' to >> > china-pm-request at pm.org >> > >> > You can reach the person managing the list at >> > china-pm-owner at pm.org >> > >> > When replying, please edit your Subject line so it is more specific >> > than "Re: Contents of China-pm digest..." >> > >> > >> > Today's Topics: >> > >> > 1. Re: China-pm Digest, Vol 43, Issue 21 (truncatei) >> > >> > >> > ---------------------------------------------------------------------- >> > >> > Message: 1 >> > Date: Mon, 17 Nov 2008 22:01:40 +0800 >> > From: truncatei >> > Subject: Re: [PerlChina] China-pm Digest, Vol 43, Issue 21 >> > To: china-pm at pm.org >> > Message-ID: >> > >> > Content-Type: text/plain; charset="utf-8" >> > >> > 2008/11/17 owen nirvana >> > >> >> 谢谢,问题是归到上一行这样的操作,我不知道如何用正则表达式完成,那不等于是让表达式再回溯吗 >> >> gtalk:freeespeech at gmail.com < >> gtalk%3Afreeespeech at gmail.com > >> >> >> >> >> >> >> >> >> >> >> >> >> 还有一个问题,是关于提取数据的 >> >> >> >> >> >> 2222 eewweasdds,asdasd.sadsadasdas >> >> >> ddasdddddddddddddddddddda >> >> >> ddddddddddddddddddddddddddd >> >> >> 2821 easdddddddddddddddddddddddd >> >> >> 2192 288888888888888888888ass0a-das. >> >> >> as;dddsaddaa0---------22222222 >> >> >> >> >> >> 诸如此类,左边很好办,可是右边并不限于单行,我该如何把这样的数据提取为 name title的格式存到数据表里呢 >> >> >> >> >> > >> > >> > >> > my ($name, $title); >> > while (<>){ >> > if (/^(\d+)\s+(.*)$) { >> > if ($name) { >> > // 保存上一个 save $name, $title >> > // 下面开始处理一个新的 >> > $name = ''; >> > $title = ''; >> > } >> > $name = $1; >> > $title .= $2; >> > } elsif(/^\s+(.*)$/) { >> > $title .= $1; >> > } >> > // save last one >> > >> > 好久不写了,上面的代码或许会有些错误,大概的流程整理出来了: >> > 每次遇到数字就开始一条数据,否则视为向当前数据中添加title >> > >> > >> > -- >> > >> "老是呆在那里不好,我们随生活需要四处迁徙,多年以来的梦想,至今还未实现,压力堵塞了我们的耳朵,工作生涯到了尽头,还是一无所有,我们应该给后人留下点儿什么,教训是不会刻在纪念碑上的,光荣的命令和指引之手,也可请求,简单地改变一下角度就足够了" >> > -------------- next part -------------- >> > An HTML attachment was scrubbed... >> > URL: < >> http://mail.pm.org/pipermail/china-pm/attachments/20081117/e8fdbb3d/attachment-0001.html >> > >> > >> > ------------------------------ >> > >> > _______________________________________________ >> > China-pm mailing list >> > China-pm at pm.org >> > http://mail.pm.org/mailman/listinfo/china-pm >> > >> > End of China-pm Digest, Vol 43, Issue 23 >> > **************************************** >> > >> _______________________________________________ >> China-pm mailing list >> China-pm at pm.org >> http://mail.pm.org/mailman/listinfo/china-pm > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > _______________________________________________ > China-pm mailing list > China-pm at pm.org > http://mail.pm.org/mailman/listinfo/china-pm > > End of China-pm Digest, Vol 46, Issue 2 > *************************************** >