Welcome to the Monastery and welcome to Perl!

The first error you are probably getting is from this line:

my $outfile = "$accession_$biotype";

The dollar sign signifies a variable name, and the double quotes are trying to interpolate a variable which you have not declared yet with my. If you really want an output file named $accession_$biotype with literal dollar sign characters in it, you could try using single quotes to prevent interpolation, and hence, to make Perl understand that it is just a string, not a variable name:

my $outfile = '$accession_$biotype';

But, what I really think you are trying to do is to keep opening a new output file with a different name. In that case, somewhere inside your loops, you would:

$outfile = "${accession}_${biotype}";

or, equivalently:

$outfile = $accession . '_' . $biotype;

Update: maybe you are looking for something close to this UNTESTED code:

use strict; use warnings; my $genfile = "c:\bemisia_coi.gb"; my $outfile; my ($OUT, $IN); print "Input: $genfile\n"; open $IN, '<', $genfile or die "cannot open $genfile: $!\n"; while (<$IN>) { $_ = lc $_; #case insensitive my @tokens = split m{//}; for my $token (@tokens) { my ($accession) = ($token =~ /locus\s*([a-z]{8})/); my ($biotype) = ($token =~ /biotype: ([a-z]{1})/); my ($sequence) = ($token =~ /origin(\*+)\/\//); $sequence =~ s/\s//g; #Removing spaces $sequence =~ s/\d//g; #Removing numbers $outfile = "${accession}_${biotype}"; open $OUT, '>' $outfile or die "cannot open $outfile: $!\n"; print "Printing to $outfile \n"; print $OUT, ">$outfile/n^^/n$sequence"); } }

In reply to Re: Spltting Genbank File by toolic
in thread Spltting Genbank File by perl_n00b

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.