Text Processing Functions
The split function
Definition
The split function splits a string to a
list
of substrings according to the positions of a given delimiter.
The delimiter is written as a pattern enclosed by slashes:
/PATTERN/.
Examples:
-
$string = "programming::course::for::bioinformatics";
@list = split (/::/, $string);
# @list is now ("programming", "course", "for", "bioinformatics")
# $string remains unchanged.
-
$string = "protein kinase C\t450 Kilodaltons\t120 Kilobases";
@list = split (/\t/, $string); #\t indicates tab
# @list is now ("protein kinase C", "450 Kilodaltons", "120 Kilobases")
You can assign the result of the split function to an array
containing
a list of scalar variable names.
Example:
$string = "protein kinase C\t450 Kilodaltons\t120 Kilobases";
($name, $mol_weight, $seq_length) = split (/\t/, $string);
# Now $name contains "protein kinase C"
$mol_weight contains "450 Kilodaltons" and
$seq_length contains "120 Kilobases".
Next.