Hi, all,
Hello,
I am a newbie for perl. I am learning perl for my biological data analysis. Now, I have a data look like this:
>I do not need-1 .....................(dots mean data here) ................. ................. >I do not need -2 ...................... ............................. >What I need-1 ............................. ............................... ..................... ......................... >what I need-2 ...................................... ................................... ................................... >>I do not need-3 ................................. ...................... ................... ...............
Because there are more than 20,000 items of "what I need" in the source file. I need write a perl script to extract all the items of "what I need" and their data. That's means, I need produce a file contains all the following data:
>What I need-1 ............................. ............................... ..................... ......................... >what I need-2 ...................................... ................................... ...................................
My program is like this, I do not know how to get the data below the ">what I need-*". Can you kindly give me some suggestions?
#!/usr/bin/perl -w
use strict;
my $outfile = "test..res"; my $infile= "Source_data"; my @source; my $line;
open INPUT, "$infile" or die "can not open $infile"; open OUTPUT, ">$outfile" or die "can not write $outfile"; @source = <INPUT>;
foreach $line(@source){ if ($line =~ /What I need/){ print OUTPUT "$line"; ..?????...................... ..?????................ } }
close INPUT;
close OUTPUT;
It looks like you need to change the Input Record Separator to some thing more appropriate. Something like:
#!/usr/bin/perl -w use strict;
my $outfile = 'test..res'; my $infile = 'Source_data';
open INPUT, '<', $infile or die "can not open $infile: $!"; open OUTPUT, '>', $outfile or die "can not write $outfile: $!";
$/ = "\n >"; # Change the Input Record Separator
while ( my $record = <INPUT> ) { if ( $record =~ /^What I need/ ) { print OUTPUT $record; } }
close INPUT; close OUTPUT;
__END__
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>