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 --------------------
In reply to Re: splitting a large text file and output
by 7stud
in thread splitting a large text file and output
by research_guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |