Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Parsing hash reference as argument for subroutine

by choroba (Abbot)
on Jan 06, 2014 at 11:48 UTC ( #1069489=note: print w/ replies, xml ) Need Help??


in reply to Parsing hash reference as argument for subroutine

I added use strict; use warnings; and fixed the reported problems. I also added some whitespace to make the code more readable and populated some variables to get any output:

#!/usr/bin/perl use warnings; use strict; my @aminos = qw(a b c); my $matrix; my $ratesfromfreq = {a => {a => 2, b => 1, c => 3}, b => {a => 3, b => 2, c => 4}, c => {a => .4, b => .3, c => .1}}; my $factor = .2; sub Matrix { for my $key (@aminos) { for my $key2 (@aminos) { $matrix->{$key}{$key2} = $ratesfromfreq->{$key}{$key2} * $ +factor; } $matrix->{$key}{$key} += (1 - $factor); } return $matrix; } sub printMatrix1 { my $matrix2; ($matrix2) = @_; for my $key (sort keys %$matrix2) { print $key . " " x 2; for my $key2 (sort keys %{ $matrix2->{$key}} ) { printf '%.5f ', $matrix2->{$key}{$key2}; } print "\n" x 2; } } my $P= Matrix(); printMatrix1($P);

Output:

a 1.20000 0.20000 0.60000 b 0.60000 1.20000 0.80000 c 0.08000 0.06000 0.82000
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Parsing hash reference as argument for subroutine
Select or Download Code
Re^2: Parsing hash reference as argument for subroutine
by madM (Beadle) on Jan 06, 2014 at 12:31 UTC
    thankyou!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-22 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (186 votes), past polls