I would like to optimize this Perl:
push_csv($string,$addthis,$position);
to place the lines inside the CSV line.
eg. if $string="one,two,,four"; $addthis="three"; $position=2;
it push_csv($string,$addthis,$position)changes the value$string = "one,two,three,four";
sub push_csv {
my @fields = split /,/, $_[0];
$_[1] =~ s/,//g;
$fields[$_[2]] = $_[1];
$_[0] = join ",", @fields;
}
This is a bottleneck in my code, as it needs to be called several million times.
If you own Perl, can you take a look at it and suggest optimizations / alternatives? Thanks in advance!:)
EDIT: Converting to @fields and back to a string takes a lot of time, I just thought about how to speed it up, where I have more than one subtitle per line. Separate once, then click multiple elements into an array, then attach once to the end.
source
share