http://qs321.pair.com?node_id=1118284


in reply to Listing occurence of all residues

Hi sreya,

I would have love to see the result your code was giving. However, If I may advice I will say use warnings and strict in your perl code ALWAYS.
There are also several modern way of doing what you want done. Like your open, using a 3-arguments is preferred.
All that been said, you could get around your code issue like so:

use warnings; use strict; use Data::Dumper; my %data; my $header; while (<DATA>) { chomp; next if /^$/; # skip on blanck line if (/^>\D+?(\d+?)$/) { $header = $1; } else { $data{$header}{$_}++ for split //, $_; } } print Dumper \%data; __DATA__ >header1 aaaaabbbb ccccddd >header2 ggggg jjj kkkk
OUTPUT:
$VAR1 = { '1' => { 'a' => 5, 'b' => 4, 'c' => 4, 'd' => 3 }, '2' => { 'g' => 5, 'j' => 3, 'k' => 4 } };
How to display the output as desired, that is for the OP! :)

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me