Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: What is wrong in this code???

by Kenosis (Priest)
on Dec 07, 2012 at 22:50 UTC ( #1007835=note: print w/ replies, xml ) Need Help??


in reply to Re^2: What is wrong in this code???
in thread What is wrong in this code???

My apologies; I did misunderstand. The following should work:

use strict; use warnings; my %sequences; while (<>) { my $i = 1; for my $char ( split '', (split)[1] ) { $sequences{ $i++ }{$char}++; } } for my $pos ( sort { $a <=> $b } keys %sequences ) { my @charCount; while ( my ( $char, $count ) = each %{ $sequences{$pos} } ) { push @charCount, "$char:$count"; } print "POS #$pos " . ( join ' | ', @charCount ) . "\n"; }

This is the output:

POS #1 a:4 POS #2 q:1 | b:3 POS #3 c:4 POS #4 x:1 | d:2 | z:1 POS #5 e:4 POS #6 f:4 POS #7 c:1 | a:1 | b:1 | d:1 POS #8 h:4 POS #9 i:4 POS #10 j:4

Run on this data:

12 abcdefahij 12 abcdefbhij 12 aqcxefchij 12 abczefdhij


Comment on Re^3: What is wrong in this code???
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-08-01 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls