in reply to can i avoid all these nested hashes
Often, depending upon other usage, it makes sense to avoid deeply nested hashes by combining the keys into a single key.
Ie: instead of:
my %snp; for my $snpId ( ... ) { for my $geneId ( ... ) { for my $transcriptId ( ... ) { for my $propertyId ( ... ) { $snp{ $snpId }{ $geneId }{ $TranscriptId }{ $propertyI +d } = ...; } } } }
Use:
my %snp; for my $snpId ( ... ) { for my $geneId ( ... ) { for my $transcriptId ( ... ) { for my $propertyId ( ... ) { $snp{ join $;, $snpId, $geneId, $TranscriptId, $proper +tyId } = ...; } } } }
The result is a single level hash with very similar selection properties to the multilevel hash, that uses far less memory, is faster to access, and far, far easier to compare one with another.
$; is a control character--ascii 28--which is unlikely to appear in any normal text hash key, is used to join the keys together to form a composite key. In the unlikely event that there is the possibility of your Ids containing that character, then there are other characters that can be used to delimit the join that may be preferable. Eg, the null character (chr(0)) or chr(255) (sometimes labelled DEL), which may be better candidates. If your ids can be unicode, you may need to be more selective.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: can i avoid all these nested hashes
by Anonymous Monk on Dec 16, 2010 at 01:12 UTC |