On a tangent, my experience may or may not be useful, but here's what i've tried in the past.

Since you're trying to read in a record, you might consider making a record object. Than you can say something like this to read in a record:

use myRecord; open FILE, $file or carp "Couldn't open file $file: $!"; while (my $record = new myRecord(\*FILE)) {
And the new method in the myRecord class would take the filehandle, do some appropriate checks (if it's open, if the first line you read contains the begin block for the record; useful stuff) and store the newly read record in the object. Then you make the typical accessor methods to get at whatever you need, and the object behaves (relatively) like a hash.

The advantages of this style of coding is that if the format ever changes (and it will sometime) you can go into the object and change the way it reads without having to change any part of the rest of the program. It also allows you to sling the records around a little more easily as they're encapsulated.

The disadvantages are that you now have to check the filehandle and you have to write the object in the first place :-)

It's up to you, HTH,
jynx


In reply to Re: how to hash this by jynx
in thread how to hash this by malaga

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.