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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1118284]
help
Chatterbox?
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
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?