Hi Everybody

I've been writing a script to automate the averaging of a set of values from text files, before performing some transformations on them. In order to do this I have needed to define lists containing the identity of the parts of the text file I'm wanting to average (in this case, the residue numbers for protein domains). Initally I set up several seperate lists (@domain_A, @domain_B...) and to test whether a residue was in that list used the vec command as below

my $A; my $i; my @domain_A = (1..119); for (@domain_A) { vec($A,$_,1) = 1 } for ( $i = -100 ; $i <= 2000 ; $i++ ) { if (vec($A,$i,1)){ print "\t $i recognised as part of the 1st domain using the ol +d method\n"; } }
This worked well. However, to make the script easier to apply to other problems, I am changing to using a multidimensional array. However performing a similar search no longer works and I'm not sure why, or if i can continuing using the vec command. Any advice would be much appreciated, as this is thoroughly confusing me.
my @domains = ( [1..119], [325..648], [649..879], [880..1110], [1111..1229], [1230..1354] ); my $i; my @total_coords = (); for ( $i = 0 ; $i <= 5 ; $i++ ) { push @total_coords, ( [0,0,0] ); my $scratch = "domains$i" ; for (@{$domains[$i]}) { vec($scratch,$_,1) = 1} } for ( $i = -100 ; $i <= 2000 ; $i++ ) { if (vec("domains$i",$i,1)){ print "\t $i recognised as part of the 1st domain using the ne +w method\n"; } }
Thanks in advance

Ben


In reply to Using vec to search an array by b_hall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.