Hi folks! I am still having difficulties with the basics: reading, matching and printing. I would appreciate if you could help me figure out the mistakes I have been making in the following code. Thanks!
#!/usr/bin/perl use strict; use warnings; my $cds = ''; my $version = ''; my $gi = ''; my @genbank = (); my $data_file ="/DATA/GenBankFile.gb"; open(INFILE, $data_file) || die("Could not open file!"); @genbank=<INFILE>; close(INFILE); foreach my $line (@genbank) { if( $line =~ /^\/\/\n/ ) { last;} elsif($line =~ /^VERSION/) { $line =~ s/^VERSION\s*\w*\S\d*\s*\w*\S//; + $version = $line;} elsif($line =~ /^\s*\Sdb_xref="GI/) { chomp($line); $line =~ s/^\s*\Sd +b_xref="GI://; $gi = $line;} elsif($line =~ /^\s*CDS/){ chomp($line); $line =~ s/^\s*CDS\s*//; $cds + = $line;} print "$gi"."\t"."$version"."\t"."$cds\n" if (defined $cds and defined + $gi and defined $version); }
and here is the data I have been reading:
LOCUS NC_0000230 600020 bp DNA linear CON 21- +APR-2007 VERSION NC_000023.10 GI:123456789 CDS join(11111..222222,333333..444444) /db_xref="GI:5555555" CDS join(66666..7777777,888888..99999) /db_xref="GI:10101010" //
and here is the far-from-the-desired-output:
123456789 123456789 join(11111..222222,333333..444444) 5555555" 123456789 join(11111..222222,333333..444444) 5555555" 123456789 join(66666..7777777,888888..99999) 10101010" 123456789 join(66666..7777777,888888..99999) 10101010" 123456789 join(66666..7777777,888888..99999)
and here is what the output should look like:
5555555 123456789 join(11111..222222,333333..444444) 10101010 123456789 join(66666..7777777,888888..99999)

In reply to Read, match string and print by sophix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.