If you are sure that every 5 lines is a record, you might just read 5 lines and get the user id from the first line. As a safety mechanism you could test wether the uid line has a string of at least 15 non-space characters at the beginning.

Better would be to check for the uid line, but is there anything in the uid line that can't occur on any other line? Maybe that the user id line starts with 5 numeric digits, then 3 alpha digits. This could be tested with  if ($line=~/^\d{5}[a-zA-Z]{3}\w{6}/) { ....

If you have something to identify the line, the following (untested) code might work

my %allids=(); my $quo=''; while (my $line=<INP>) { if ($line=~ ... ) { $allids{substr($quo->[0],8,6)}= $quo if $quo; $quo=[$line]; } else { push @$quo, $line; } }

After that you should be able to access the array of lines for id 000123 with @{$allids{'000123'}}

UPDATE: PS: You say that substr 9-14 is the id, but in your example both records have the same numbers in the columns 9 to 14 (no matter if you counted from 0 or 1).


In reply to Re: Hash Help by jethro
in thread Hash Help by mmittiga17

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.