Is there an elegant zip to interleave two lists in Perl 5?

后端 未结 7 780
一向
一向 2020-12-02 15:45

I recently \"needed\" a zip function in Perl 5 (while I was thinking about How do I calculate relative time?), i.e. a function that takes two lists and \"zips\" them togethe

7条回答
  •  Happy的楠姐
    2020-12-02 16:30

    Algorithm::Loops is really nice if you do much of this kind of thing.

    My own code:

    sub zip { @_[map $_&1 ? $_>>1 : ($_>>1)+($#_>>1), 1..@_] }
    

提交回复
热议问题