Greetings, fellow Monks.

I need help with yet another problem. I want to test the next line in a file to see if it is a certain type, or a new data set, or the end of file. Any idea how I can do this? Here's what I have so far:

open(IN, '<', $file) or die "Couldn't open $file for reading: $!\n\n"; my (@hdr, %stn, %seg); my ($lname); while (<IN>) { if (/^H/ ... /[<\[]/) ## If it's a header line... { push(@hdr, $_); ## ...add it to @hdr next; } next if (/reclin/i); ## If it's a DISCO header, ignore; continue to ## next iteration ## Not a header, so must be data.... ( $lname = substr($_,1,16) ) =~ s/\s+//g; ( my $s = substr($_,17,8) ) =~ s/\s+//g; ( my $x = substr($_,45,8) ) =~ s/\s+//g; ( my $y = substr($_,53,8) ) =~ s/\s+//g; ( my $z = substr($_,61,5) ) =~ s/\s+//g; $stn{$s} = [ $x, $y, $z ]; ## HoA: Keys = Stn ID ## Value = Stn Coords

This builds an HoA of station numbers and coordinates. After this point, I want to check if the next line is a header line (/^H/ or /reclin/) or data from another seismic line. (The first header line always starts with 'H'.) If it is any of those, I want to "save" the current %stn hash and @hdr array to a hash as follows:

$seg{$lname} = { 'header' => \@hdr, 'stations' => \%stn, };

(I think I've done the references correctly.) Then I need to clear the @hdr array and %stn hash to get ready for the next set of data. Data samples follow.

Data Sample, Case 1:

__DATA__ 80-101 412 54175659N114551423W 635314260187896 6756 80-101 413 54175657N114551794W 635247260187870 6760 80-101 414 54175655N114552165W 635180260187843 6775 80-101 415 54175653N114552535W 635113360187817 6748 80-101 416 54175650N114552905W 635046560187790 6721 H CLIENT : ************* H PROSPECT : ************* H CONTRACTOR : CANJAY EXPLORATION LINE NAME : 80-103 H SURVEY CO. : CANJAY EXP. UNIQUE ID : *******

Data Sample, Case 2:

__DATA__ 80-101 412 54175659N114551423W 635314260187896 6756 80-101 413 54175657N114551794W 635247260187870 6760 80-101 414 54175655N114552165W 635180260187843 6775 80-101 415 54175653N114552535W 635113360187817 6748 80-101 416 54175650N114552905W 635046560187790 6721 80-103 224 54160602N114433190W 648117760157647 6774 80-103 225 54160602N114433561W 648050760157627 6769 80-103 226 54160602N114433931W 647983760157606 6763 80-103 227 54160602N114434302W 647916760157585 6758 80-103 228 54160603N114434672W 647849760157564 6753

In reply to Matching next line in text file by YYCseismic

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.