Perl sub优化使用split将字符串推入csv
发布时间:2020-12-16 06:27:09 所属栏目:大数据 来源:网络整理
导读:我想优化这个Perl子: push_csv($字符串,$前页,$位置); 用于将字符串放在CSV字符串中. 例如if $string =“one,two,four”; $前页= “三包”; $位置= 2; 然后push_csv($string,$addthis,$position)将改变$string =“one,three,four”的值; sub push_csv { my
我想优化这个Perl子:
push_csv($字符串,$前页,$位置); 用于将字符串放在CSV字符串中. 例如if $string =“one,two,four”; $前页= “三包”; $位置= 2; 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,你能看看它,并提出优化/替代方案吗?提前致谢! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |