in reply to Re: Using the second word in a line to split a file into multiple files
in thread Using the second word in a line to split a file into multiple files
But it doesn't work for the actual data I am parsing. My data file format is actually more like the following: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);
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using the second word in a line to split a file into multiple files
by haukex (Archbishop) on Aug 26, 2019 at 14:42 UTC |