in reply to Read, match string and print
Your first mistake is assigning values to $cds, $version and $gi and then using the test defined $cds and defined $gi and defined $version on values that are always defined. And then your next mistake is not clearing out the values in the variables after you have printed them.
What you need is something more like this:
#!/usr/bin/perl use strict; use warnings; my $data_file = '/DATA/GenBankFile.gb'; open INFILE, '<', $data_file or die "Could not open '$data_file' $!"; my ( $cds, $gi, $version ); while ( <INFILE> ) { last if m!//$!; if ( /^VERSION.*\w:(\d+)/ ) { $version = $1; } elsif ( /^\s*\Sdb_xref="GI:(\d+)/ ) { $gi = $1; } elsif ( /^\s*CDS\s*(\S+)/ ) { $cds = $1; } if ( defined $cds && defined $gi && defined $version ) { print "$gi\t$version\t$cds\n"; $gi = $cds = undef; } } close INFILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read, match string and print
by sophix (Sexton) on Feb 08, 2010 at 07:37 UTC | |
by jwkrahn (Abbot) on Feb 08, 2010 at 09:00 UTC | |
by sophix (Sexton) on Feb 08, 2010 at 09:26 UTC | |
by Corion (Patriarch) on Feb 08, 2010 at 09:32 UTC | |
by sophix (Sexton) on Feb 08, 2010 at 09:47 UTC | |
|