babysFirstPerl:

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.


In reply to Re: More efficient way to exclude footers by roboticus
in thread More efficient way to exclude footers by babysFirstPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.