I believe there's an easier solution that hasn't been mentioned yet.

You said in your question that "special tag starts record off".

That's your answer. Right now you're reading in line by line, but you should instead, read the file in record by record. That's pretty easy to do if the special tag is in some way uniform. Let's say the special tag is "<RECORD>". Set the input record separator to that instead of newline, and then read records in their entirety. At that point, if you still need to further split things down using newlines as delimeters, you can split on newline at that point. Here's how:

{ local $/ = "<RECORD>"; open INFILE, "<in.dat" or die "Bleah!\n$!"; while ( my $record = <INFILE> ) { chomp $record; # strip off the record separator. my @rec_lines = split /\n/, $record; # process each record line here. } close INFILE; }

I hope this helps!


Dave


In reply to Re: unreadline function? by davido
in thread unreadline function? by aquarium

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.