in reply to More efficient way to exclude footers
Since your file is small, you might just want to read the file into memory, chop off the header and footer using a hash slice, and then process the rest:
$numHeaders= $ARGV[0]; $numFooters= $ARGV[1]; # Read the file into memory open (INPUT, $l_infile); my @file = <INPUT>; close INPUT; # Treating the array as a scalar value gives you the number of lines # (not that you really need to worry about this right now) my $numLines = @file; # Split the headers and footers into their own arrays my @headers = splice @file, 0, $numHeaders; my @footers = splice @file, $#file-$numFooters, $numFooters; for my $line (@headers) { # do whatever you want with the headers } for my $line (@file) { # process your data }
The splice function(perldoc -f splice) returns whatever you chop out of your array, so if you don't want the headers or footers, just don't save them into new variables.
# Discard the headers and footers splice @file, 0, $numHeaders; splice @file, $#file-$numFooters, $numFooters;
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|