b_hall has asked for the wisdom of the Perl Monks concerning the following question:
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
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 $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"; } }
Thanks in advancemy @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"; } }
Ben
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using vec to search an array
by tlm (Prior) on Jun 15, 2005 at 13:28 UTC | |
|
Re: Using vec to search an array
by monarch (Priest) on Jun 15, 2005 at 13:32 UTC | |
|
Re: Using vec to search an array
by Tomtom (Scribe) on Jun 15, 2005 at 13:30 UTC | |
by b_hall (Scribe) on Jun 15, 2005 at 13:50 UTC |