如何使用带分割功能的地图来修剪组成部分:$ a,$ b,$ c和$ d; $行?在Perl中使用拆分和修剪的地图
my ($a, $b, $c, $d, $e) = split(/\t/, $line);
# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
我担心引入模块上的依赖它说“最终版本,该版本字符串::的Util不再是正在开发或支撑。 “。 – 2010-07-02 03:05:49
如果我们要安装一个CPAN模块,我们不妨使用最好的工作:['String :: Strip'](http://p3rl.org/String:Strip)。见http://www.illusori.co.uk/perl/2010/03/05/advanced_benchmark_analysis_1.html – daxim 2010-07-02 09:23:05
我还没有尝试过,但对于这些模块的酸性测试是否它们去掉了Unicode 0x3000来自字符串。如果不是,那么它可能不是一个好的替代品。纵观源代码,String :: Strip使用C函数'isspace'去掉空格,并且不知道unicode,所以它的行为与上述不同。 – 2010-07-02 09:58:35