in reply to printing complex data structures
Please note my naming convention using trailing h_ and a_ to denote hash refs and array refs.
i.e. h_codes -> h_planet -> a_aa see included dump
Like this it's obvious when to use @$a_ and %$h_ for dereferencing ...
use strict; use warnings; use Data::Dump qw /pp dd/; my %aas = ( 'serine' => ['TCA', 'TCC', 'TCG', 'TCT'], 'proline' => ['CCA', 'CCC', 'CCG', 'CCT'] ); my %codes; $codes{'earth'} = \%aas; $codes{'mars'} = { 'serine' => ['QWZ', 'QWX', 'QWW'], 'proline' => ['ZXZ', 'ZXX', 'ZXQ', 'ZXW'] }; dd \%codes; # dump for clarity base_code (\%codes); sub base_code { my ($h_codes) = @_; for my $h_planet (values %$h_codes) { for my $a_aa (values %$h_planet) { # for my $codon ( @$a_aa ) { print $codon, "\n"; } } } }
{ earth => { proline => ["CCA", "CCC", "CCG", "CCT"], serine => ["TCA", "TCC", "TCG", "TCT"], }, mars => { proline => ["ZXZ", "ZXX", "ZXQ", "ZXW"], serine => ["QWZ", "QWX", "QWW"], }, } TCA TCC TCG TCT CCA CCC CCG CCT QWZ QWX QWW ZXZ ZXX ZXQ ZXW
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: printing complex data structures (values)
by AnomalousMonk (Archbishop) on Jul 24, 2017 at 16:35 UTC | |
by LanX (Saint) on Jul 24, 2017 at 16:50 UTC | |
|
Re^2: printing complex data structures (values)
by stevieb (Canon) on Jul 24, 2017 at 15:40 UTC | |
|
Re^2: printing complex data structures (values)
by ic23oluk (Sexton) on Jul 24, 2017 at 15:51 UTC |