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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |