Here is one way:
#! perl use strict; use warnings; use Data::Dump; my %HoA_sequence = ( 67 => 'A', 68 => 'S', 77 => 'W', 78 => 'P', 79 => 'I', ); $HoA_sequence{$_} //= '-' for 67 .. 79; dd \%HoA_sequence;
Output:
21:40 >perl 904_SoPW.pl { 67 => "A", 68 => "S", 69 => "-", 70 => "-", 71 => "-", 72 => "-", 73 => "-", 74 => "-", 75 => "-", 76 => "-", 77 => "W", 78 => "P", 79 => "I", } 21:42 >
Note: the line $HoA_sequence{$_} //= '-' for 67 .. 79; could be written more verbosely as:
for my $protein (67 .. 79) { unless (exists $HoA_sequence{$protein}) { $HoA_sequence{$protein} = '-'; } }
which may be clearer if you’re not comfortable with Perl’s defined-or operator and statement modifiers.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: How to add missing part in a Hash of Array
by Athanasius
in thread How to add missing part in a Hash of Array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |