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