in reply to splitting a large text file and output
use strict; use warnings; use 5.010; my $str = <<"ENDOFDATA"; VECT 1 1 1 2 2 2 3 3 3 VECT 4 4 4 5 5 5 6 6 6 ENDOFDATA #open() your original file here: open my $INFILE, '<', \$str or die "Couldn't read from string: $!"; my $section_counter = 1; { local $/ = ""; #tell perl that the end of a line will #be reached when perl encounters any #number of consecutive blank lines while (my $section = <$INFILE>){ chomp($section); my $fname = "file$section_counter"; say $fname; say $section; #or write to a file say '-' x 20; $section_counter++; } } close $INFILE; --output:-- file1 VECT 1 1 1 2 2 2 3 3 3 -------------------- file2 VECT 4 4 4 5 5 5 6 6 6 --------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting a large text file and output
by johngg (Canon) on Jun 10, 2011 at 22:22 UTC |