« Final Push for Version 17 | Main | General Cleanup of Drug Target Files »

Processing Tab-Delimited Files

The Tracer.pm module contains several utilities for processing tab-delimited files. Although none of these methods do anything spectacular, they take some of the tedium out of this kind of programming.

  • Open opens a file and dies with an error message if the open fails.
  • GetLine reads a line from the file, chops off the new-line, and splits it into pieces on tab boundaries.
  • PutLine takes a list of text elements, joins them together with tabs, appends a new-line, and writes the result. This is basically the opposite of GetLine.

A sample program using these methods is shown below the fold.

use Tracer;

# ... Initialization goes here ...
my $inh = Open(undef, "<$inputFileName");
my $outh = Open(undef, ">$outputFileName");
while (! eof $inh) {
    my @fields = Tracer::GetLine($inh);
    #
    # process input fields, produce @outFields
    #
    Tracer::PutLine($outh);
}
close $inh;
close $outh;

Leave a comment

HTML is not allowed in comments; however, if you put in a raw URL (http://www.somewhere.com/page.html) it will automatically be converted to a link.. Also, it is likely your comment will not appear unless you refresh the page manually after posting it.

About

This page contains a single entry from the blog posted on December 6, 2006 4:28 PM.

The previous post in this blog was Final Push for Version 17.

The next post in this blog is General Cleanup of Drug Target Files.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 4.01