Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Listing occurence of all residues

by 2teez (Vicar)
on Mar 01, 2015 at 15:07 UTC ( #1118284=note: print w/replies, xml ) Need Help??

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
$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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1118284]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-04-16 02:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found