open my $fh, '<', $file or die "failed open file: $!";
my $arr = [];
my $beginParagraph = 'begin'; # mark start the particular paragraph
my $endParagraph = 'end'; # mark end the particular paragraph
while ( <$fh> ){
if ( /$beginParagraph/ .. /$endParagraph/ ) {
push @{ $arr->[$.] }, split /\./; # i assume string end '.'
}
}
update
use strict;
use warnings;
use Data::Dumper;
my $arr;
my $beginParagraph = 'Here starts the second paragraph'; # mark star
+t the particular paragraph
my $endParagraph = 'And this is the second line of it'; # mark en
+d the particular paragraph
while ( <DATA> ){
if ( /$beginParagraph/ .. /$endParagraph/ ) {
chomp;
push @$arr, split /\s+/;
}
}
print Dumper($arr);
__DATA__
This is the start of the first paragraph.
This is the second line of this first paragraph.
And this is the last line of it.
Here starts the second paragraph. And this is the second string.
This is the second line of this second paragraph.
And this is the second line of it.
Here starts the third paragraph.
This is the second line of this
Output:
$VAR1 = [
'Here',
'starts',
'the',
'second',
'paragraph.',
'And',
'this',
'is',
'the',
'second',
'string.',
'This',
'is',
'the',
'second',
'line',
'of',
'this',
'second',
'paragraph.',
'And',
'this',
'is',
'the',
'second',
'line',
'of',
'it.'
];
|