Hello Monks,
I have trouble with complex data structures and I'm currently wondering why the following code doesn't work:
use strict; use warnings; sub base_code (\%); 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'] }; base_code (%codes); ## line 17 sub base_code (\%) { my $h_ref = $_[0]; foreach my $planet (keys %$h_ref){ foreach my $aa (keys %$planet){ + ## line 22 foreach my $codon (@{ $planet->{$aa} }){ print $codon, "\n"; } } } }
the error message is: Can't use string ("earth") as a HASH ref while "strict refs" in use at ex9.pl line 22.
Can anyone help? Thanks in advance :)
for extra credits: Why does it complain if I write base_code (\%codes) in line 17 ? I thought it must be a reference..
In reply to printing complex data structures by ic23oluk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |