in reply to Spltting Genbank File
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"); } }
|
|---|