in reply to Running a string through a filter program and recieving the output as a string
Piping things to external programs is slow. Starting up sed will involve many microseconds or even milliseconds to spawn an external process, and if you do this in an inner loop, once for each of a few million words, it soon adds up to a long time. It's also unneccessary, since Perl has the ability to perform such transformations itself:
my $old = 'hat|coat|shoe'; my %new = ( cap => 'hat', jacket => 'coat', shoe => 'boot', ); for my $word ( @words ) { $word =~ tr/[A-Za-z]/[M-ZA-Lm-za-l]/; # decode ROT13 $word =~ s/($old)/$new{$1}/ei; # convert cheap clothes int +o expensive ones }
--
TTTATCGGTCGTTATATAGATGTTTGCA
|
|---|