2009年10月19日星期一

[PerlChina] Re: map提取数据时,如何同时执行正则?

apply {$_->{content} if s/<(.+?)>//gi} @$topics更好些。

On 10月19日, 下午5时01分, TBY <tangbo...@hotmail.com> wrote:
> 其实楼主这个问题
> 应该可以这么转换:
> Use List::MoreUtils;
> @content = apply {$_ =~ s/<(.+?)>//gi; $_->{content}} @$topics
> 或者先把原来的数组复制个副本再用map做就可以了。
>
> 一般来说用for产生新数组效率不如map,因为每个循环中都使用push等手段,需要每次都请求分配内存。楼主这个新数组元素数目是未知的,无法预先
> 请求预支相应数目的内存。
>
> 详见Perl Best Practice page 110。
>
> On 10月19日, 上午11时35分, liseen <liseen....@gmail.com> wrote:
>
>
>
> > 呵呵, best practice 里面有段专门讨论这个。
>
> > 2009/10/19 Tiger Peng <tigerpeng2...@gmail.com>
>
> > > 为什么不benchmark一下?
>
> > > 2009/10/18 Michael Zeng <galaxy2...@gmail.com>:
> > > > map/grep 只是看得舒服, 效率和for 一样的
>
> > > > 对于数组自身的操作(不赋指给另一个新的数组),for 要比 map/grep 效率高
>
> > > > 2009/10/18 imxae <imx365s...@gmail.com>
>
> > > >> map的循环不比foreach效率高吗?
>
> > > >> --
> > > >> Yours Sincerely
> > > >> Zeng Hong- 隐藏被引用文字 -
>
> > - 显示引用的文字 -- 隐藏被引用文字 -
>
> - 显示引用的文字 -
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

没有评论: