How to extract paragaph and selected lines with Perl
- by neversaint
I have a text that looks like this. What I want to do is
to extract the whole paragraph under
the section "Aceview summary" until the line that starts with "Please quote".
extract the line that starts with "The closest human gene".
And store them into array with two elements.
However I am stuck with the following script logic.
What's the right way to achieve that?
#!/usr/bin/perl -w
my $INFILE_file_name = $file; # input file name
open ( INFILE, '<', $INFILE_file_name )
or croak "$0 : failed to open input file $INFILE_file_name : $!\n";
my @allsum;
while ( <INFILE> ) {
chomp;
my $line = $_;
my @temp1 = ();
if ( $line =~ /^ AceView summary/ ) {
print "$line\n";
push @temp1, $line;
}
elsif( $line =~ /Please quote/) {
push @allsum, [@temp1];
@temp1 = ();
}
}
close ( INFILE ); # close input file