Perl sub优化使用split将字符串推入csv

Perl sub优化使用split将字符串推入csv,第1张

概述我想优化这个Perl子: push_csv($字符串,$前页,$位置); 用于将字符串放在CSV字符串中. 例如if $string =“one,two ,, four”; $前页= “三包”; $位置= 2; 然后push_csv($string,$addthis,$position)将改变$string =“one,two,three,four”的值; sub push_csv { 我想优化这个Perl子:

push_csv($字符串,$前页,$位置);

用于将字符串放在CSV字符串中.

例如if $string =“one,two,four”; $前页= “三包”; $位置= 2;
然后push_csv($string,$addthis,$position)将改变$string =“one,three,four”的值;

sub push_csv {    my @fIElds = split /,/,$_[0]; # split original string by commas;    $_[1] =~ s/,//g;               # remove commas in $addthis    $fIElds[$_[2]] = $_[1];        # put the $addthis string into                                   # the array position $position.    $_[0] = join ",",@fIElds;     # join the array with commas back                                   # into the string.}

这是我的代码中的瓶颈,因为它需要被称为几百万次.

如果你精通Perl,你能看看它,并提出优化/替代方案吗?提前致谢! 总结

以上是内存溢出为你收集整理的Perl sub优化使用split将字符串推入csv全部内容,希望文章能够帮你解决Perl sub优化使用split将字符串推入csv所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1257845.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存