I recently needed to parse the first few lines of some fairly large files. During my research in trying to figure out how to read just a few lines from a file, then move on to the next file, I found
Jumping out of a partially read file.
This node solve my quest for how to read just a few lines from each file. However it left me with a different question. While I'm very accustomed to opening a file and processing it line by line, I've never done this with a scalar variable (ref: $header in Jumping out of a partially read file.
I'm fairly sure the answer is simple, however in many searches on Perlmonks.org as well as Google, and of course "Learning Perl", the solution has not yet become clear.
My $header scalar contains data that looks like this:
X-Account-Key: account3
Return-Path: <>
Delivered-To: somename@somedomain.com
Received: (qmail 77369 invoked for bounce); 3 Jun 2005 06:35:09 -0000
Date: 3 Jun 2005 06:35:09 -0000
From: MAILER-DAEMON@smtp.somedomain.com
To: somename@somedomain.com
Subject: failure notice
Thanks for any suggestions,
Mike
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.