我想优化这个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,你能看看它,并提出优化/替代方案吗?提前致谢!