"Rob Dixon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Öznur tastan wrote:
> >
> > I want to store alignment results( that is why I asked about struct yesterday).
> > I thougt that I could just push seq1 seq2 and the score to an array and can
> > acess them by using $k*3 + $n ($n=0 for seq1 $n =2 for score)
> >
> > But I also have a sort of grouping of the alignment which is denoted by $p.
> > So I wanted to use a matrix so in each row I would have one group (group index
> > is $p) and in that row alignments features(seq1 seq2 score)
> >
> > I tried this:
>
> As Joseph pointed out in your other thread, using a variable name like $p
> isn't very informative. If I didn't know better I would guess that it may be
> a pointer (but those are called 'references' in Perl) but couldn't
> guess beyond that. What's wrong with $index?
>
> > $p=0;
> > $seq1="A--V";
> > $seq2="AAAV";
> > $score=-5;
> >
> > [EMAIL PROTECTED];
> > push @$ref,$seq1;
> > push @$ref,$seq2;
> > push @$ref,$score;
> >
> > when use this way it gives the error "Not an array reference".
>
> @subalignments[$p] is an array slice with one element, so [EMAIL PROTECTED]
> is a list of one scalar reference. Assigning this list to the scalar $ref
> copies the last (and only) element of the list, so $ref is now a reference
> to the scalar array element $subalignments[$p].
then is there a way to push an element to one of the arrays of a double-dimensional
array?
> > I think I should declare the-two dimensional array so i thought adding
> > $subalignments[0][0]=0 (silly I know) would work- didn't work:)
>
> There's no need to predeclare arrays in Perl, just use an array as if was
> two-dimensional and it will be. So:
>
> $subalignments[$p][0] = $seq1;
> $subalignments[$p][1] = $seq2;
> $subalignments[$p][2] = $score;
>
> or
>
> $subalignments[$p] = [$seq1, $seq2, $score];
>
> does the same thing. But I think perhaps you should be using a hash here:
>
> $subalignments[$p] = {
> seq1 => $seq1,
> seq2 => $seq2,
> score => $score,
> };
Yes that certainly is better. But $subalignments[$p] should be an array of hashes
because I want to hold the alignment group there. $subalignments[$p][$groupindex]={
seq1 => $seq1,
seq2 => $seq2,
score => $score,
};
would work but holding the $groupindex for each group is tedious so
I need the push the hashes into an row of the double dimensional array(row would be
array of hashes).
How would that be?
> Then you can access the values as
>
> $subalignments[0]{seq1};
> $subalignments[42]{score};
>
> and so on.
>
> HTH,
>
> Rob
thanks
oznur
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>