从 Perl 中包含空或空白字符的数组中删除元素

Ami*_*and 1 perl grep dictionary

我想使用 map 或 grep 将数组 @x 转换为数组 @y。

@x = ('aa','', 'bb','    ','cc', "\t");
@y = ('aa','bb','cc');
Run Code Online (Sandbox Code Playgroud)

我试过的:

#@x= grep {s/^\s+|\s+$//g} @x;  # not correct
@y = grep { $_ } @x;  # remove '' null character
Run Code Online (Sandbox Code Playgroud)

请建议更好的方法来做到这一点,最好在一行中。

yst*_*sth 5

在我看来你只是想要

@y = grep /\S/, @x;
Run Code Online (Sandbox Code Playgroud)