Perl相当于Ruby的分区函数?

Lef*_*que 1 ruby arrays perl

一个基本的例子是我有一个数组,['abc','cde','efg']并希望将它分成两个数组.一个元素包含a c和一个元素.

在红宝石中,我只想说:

has_c, no_c = arr.partition { |a| a.include?('c') }
Run Code Online (Sandbox Code Playgroud)

有一个简单的perl等价物吗?

mob*_*mob 9

有这样的part功能List::MoreUtils:

use List::MoreUtils 'part';
my $listref = [ 'abc', 'cde', 'efg' ];

my ($without_c, $with_c) = part { /c/ } @$listref;

print "with c : @$with_c\n";
print "without: @$without_c\n";
Run Code Online (Sandbox Code Playgroud)

输出:

with c : abc cde
without: efg
Run Code Online (Sandbox Code Playgroud)