G'day younggrasshopper13,
For the head part, follow the link already provided
(perlintro).
This will show you how to open a file;
read as many head lines as you need.
For the tail part, this will depend on the size and structure of the file.
Here's some options:
-
For a small file, (<$filehandle>)[-1] will give you just the last line.
If you want more than one tail line,
reverse might come in handy, depending on how you write your code.
-
For fixed-width records, using seek might be best.
-
For large files, the builtin module, Tie::File,
could be a good choice.
-
There's a variety of CPAN modules that might suit you better;
e.g. File::Tail.
You mentioned "first field" and "first column".
If that's referring to CSV, see your earlier post, "parsing CSV";
if it's something else, you'll need to be more specific.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.