[PerlChina] Perl with opensources

cnhack TNT cnhacktnt at gmail.com
Mon Oct 6 00:13:20 PDT 2008


活活,这个就和 bash 里的 brace expansion 一样:
--------

$ echo {a}-{b,c}-{d,e,f}-{a}

-------

确实是有趣的用法 :-)


2008/10/6 agentzh <agentzh at gmail.com>

> 2008/10/6 Jeff Peng <jeffpeng at gmx.net>
>
>> 例如,对这么一组数据:
>> {a}-{b,c}-{d,e,f}-{a}
>> 每组里抽一个字母,写出所有组合(按顺序)。
>> 我想了下,自己用一堆的map{}也七七八八能搞定,但Randal用一行就搞定了:
>>
>> my @result = glob "{a}-{b,c}-{d,e,f}-{a}";
>>
>>
> 这个一定要顶。。。原来 glob 也能这么用。。。哈哈!
>
> Haskell 里可以这么写:
>
>    [ Data.List.intersperse '-' [u,v,w,x] | u <- "a", v <- "bc", w <- "def",
> x <- "a"]
>
> GHCi 的输出是
>
>    ["a-b-d-a","a-b-e-a","a-b-f-a","a-c-d-a","a-c-e-a","a-c-f-a"]
>
> 在 Python, Erlang 等支持 list comprehension 的语言里都可以写成这样的,呵呵。可惜。。。Perl 里没有 list
> comprehension。。。glob 在这个例子中极好,只是对于更复杂的情形还不够一般,呵呵。
>
> Thanks!
> -agentzh
>
> _______________________________________________
> 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: <http://mail.pm.org/pipermail/china-pm/attachments/20081006/ea747024/attachment.html>


More information about the China-pm mailing list