[Bioperl-l] deleting string fragments?
Jurgen Pletinckx
jurgen.pletinckx at algonomics.com
Fri Apr 2 03:33:27 EST 2004
If you know the location of your substring, rather than the
contents, the following bit is useful and fast:
substr($string,$location, $length) = '';
Yes, you are assigning an empty string to a substring.
Yes, this looks evil. It's an established use of substr,
though.
But if you need to lookup the location first (say, with
index($string, $substring)), you had better go ahead
and use the regular expression approach.
In that case, you don't need to first check whether the
substring exists, and then edit it out:
$string =~ s/$substring//g;
will happily remove any and all occurences of the sub-
string, and will do nothing if the subtring is not
present.
--
Jurgen Pletinckx
AlgoNomics NV
More information about the Bioperl-l
mailing list