Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Parsing hash reference as argument for subroutine

by choroba (Bishop)
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);


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

Replies are listed 'Best First'.
Re^2: Parsing hash reference as argument for subroutine
by madM (Beadle) on Jan 06, 2014 at 12:31 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069489]
[LanX]: edge or node?
[oiskuu]: from each height difference, there's a fixed number of "moves right" - "moves left". So it's a number of combinations.
[Discipulus]: I already know how much distinct paths exists but to demonstrate the property i want to have them all
[oiskuu]: ie C(n, k); where n is height difference, k is position in the line
[Discipulus]: infact there are 70 distinct path to reach the tale wich holds 70
[Discipulus]: what i want is to compute them

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2018-03-19 11:05 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.