�znur Tastan <[EMAIL PROTECTED]> wrote:
:
: ----- Original Message -----
: From: "Charles K. Clarkson" <[EMAIL PROTECTED]>
:
: > Unfortunately, I have no idea if I have helped or not.
:
: No you exactly helped me but now let me ask one more question.
: When using a hash of array of hashes or a hash of an array of arrays
: how can I insert an new element in if I know which group it
: belongs to?
: for example how can I insert a new alignment whose
: seq1 AAAK
: seq2 VVV-
: score 10
: into group_name_1
: without backtracking how many elements group_name_1 contains
: so something like "push"?????
push @{ $group{ group_name_1 } }, [ 'AAAK', ' VVV-', 10 ];
Or:
push @{ $group{ group_name_1 } },
{
seq1 => 'AAAK',
seq2 => ' VVV-',
score => 10
};
$group{ group_name_1 } is an array reference. They are similar
to the pointers used in C. Though not exactly the same.
Wrapping a reference with @{} dereferences the array reference
so that it can be treated as an array. For convenience you could
also use:
my $group_ref = $group{ group_name_1 };
push @$group_ref, [ 'AAAK', ' VVV-', 10 ];
Here, @$group_ref is a shortcut for @{ $group_ref }. Unfortunately,
you can't use @$group{ group_name_1 } in place of
@{ $group{ group_name_1 } }.
You can determine the number of alignments in a group by
retrieving the scalar value of its dereferenced array reference:
my $group_size = @{ $group{ group_name_1 } };
Or:
foreach my $group ( keys %groups ) {
printf "%s contains %s alignments.\n", $group, scalar @{ $groups{ $group
} };
}
An array of all groups in either data structure is in
'keys %groups'.
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>