Hello,
I am trying to print the contents of my hash to newly created files. The value of the hash is the sequence and the hash key is the ID for the sequence. I was trying to get my script to loop through my hash and create new files with the name of the files being the sequence ID and the contents being the value of the hash.
I can't figure out how to do this successfully.
Below is my script:
my %id2seq = ();
my $id = '';
open File,"human_hg19_circRNAs_putative_spliced_sequence.fa",or die $!
+;
while(<File>){
chomp;
if($_ =~ /^>(.+)/){
$id = $1;
}else{
$id2seq{$id} .= $_;
}
}
my $filename = "'$id'";
open (my $fh, '>', $filename) or die "Could not open '$filename' $!";
+
foreach $id (keys %id2seq){
print $fh ($id."\n",$id2seq{$id}, "\n");
}
close File;
close $fh;
Any pointers will be well appreciated.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.