http://www.perlmonks.org?node_id=1069489


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
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

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