Hello, thank you so much for your help and guidance, I am very new to this forum.
I was able to get this working, and you are correct, I had filecount in there from the code I was using to start out, and focused mainly on the regex problems. I was able to get it to do exactly what was needed on the test data I presented, then realized the reason it wasn't working on the actual data file I need to parse, is because I have .s in the second word, and that second word always ends with a dot. (.s)
This works for the orignal test data:
use warnings;
use strict;
my $infn = '/Users/azeller/Documents/Rogers_import/20190822_RR_export-
+nrcmd.txt';
open(my $infh, '<', $infn) or die "$infn: $!";
my $outfh;
my $filecount = 0;
while ( my $line = <$infh> ) {
if ( $line =~ /^zone\s+(\w+)\W+\w+\s*$/ ) {
close $outfh if $outfh;
my $outfn = sprintf '%sdb', $1;
open($outfh, '>', $outfn) or die "$outfn: $!";
}
if ($outfh) {
print {$outfh} $line or die "print: $!";
}
}
close($outfh) if $outfh;
close($infh);
But it doesn't work for the actual data I am parsing.
My data file format is actually more like the following:
one 1file1.nest. 1ss
record1a
record1b
record1c
record 1d 2
record empty
endoffile
zone 2file2.egg. 1ss
record1a
record1b
record1c
record 1d 2
record empty
endoffile
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.