You can save the subcontents in an array, that is easy. use Modern::Perl;
use Data::Dump qw/dump/;
my @subsections;
{
local $/ = "\n\n";
@subsections = <DATA>
}
say dump(@subsections);
__DATA__
subsection 1 line 1
subsection 1 line 2
subsection 1 line 3
subsection 1 line 4
subsection 2 line 1
subsection 2 line 2
subsection 2 line 3
subsection 3 line 1
subsection 3 line 2
subsection 3 line 3
subsection 4 line 1
subsection 4 line 2
But what file-specific operations do you want to perform on the subcontents?Update: You can use a scalar reference as a "virtual" (or in-memory) file (since Perl v5.8.0.)
open my $fh, '<', \$subsections[1];
print while <$fh>;
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|