Text Processing Functions

Example for using the split function

The file containing the Genome Database list of muscarinic acetylcholine receptor genes is written in a tab-delimited format.

The split function will help us decompose each line to a list of the fields which were originally separated by tab.

The following program extracts all accession numbers from the file.

#!/usr/bin/perl

$gdb_file = "gdb_list.txt";

open (GDB, $gdb_list_file) || die "cannot open \"$gdb_list_file\": $!";

@acc_nos = ();

while ($line = <GDB>) {
   my ($gene_symbol, $acc_no, $gene_name) = split (/\t/, $line);
   push (@acc_nos, $acc_no);
}

print "@acc_nos\n";

Program output:
GDB:125213 GDB:125214 GDB:125215 GDB:125216 GDB:125217

Table of Contents.
Previous | Next.