Hi Charles,
At 13:08 2006-9-29, Charles K. Clarkson wrote:
Shiping Wang wrote:
: Hi, I have a big array, I need re-arrange it then put into sub
: array, after that do something on each sub array.
How do you want to split it into sub arrays? Like items,
number of items, random items, ...?
: Here is my code:
[snip]
It is really hard to tell what you are attempting. We don't
know what is in @P_array, for example, because it is never defined
and @q_$i isn't a valid perl variable name. Working code would be
better.
Tell us what you want to do to the big array.
Here is my real working code:
use strict;
use warnings;
# actually this array has 90 elements, I cut it for short. I have several
thousands of this kind of arrays.
=pod
the way I need re-arrange in this way:
array0: 0, 10..17
array1: 1, 18..25
array2: 2, 26..33
.......
.......
array9: 9, 82..89
=cut
my @P_array = (
0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056,
0.046, 0.98, 0.12,
0.002,0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056,
0.046, 0.98, 0.12,
0.002,0.06,0.04,0.98,0.12,0.02,0.98,0.11,0.25,0.36,0.01,0.01,0.01,0.02,0.01,0.05,0.056,
0.046, 0.90);
my $p_cutoff = 0.01;
my $qtl_flag;
my @result;
for my $i ( 0 .. 5 ) {
for ($P_array[$i], @P_array[8*$i+10 .. 8*$i+17]){
$qtl_flag = 0;
if ($_ <= $p_cutoff){
$qtl_flag = 1;
last;
}
}
push @result, $qtl_flag;
}
print join "\t", @result, "\n";
__END__
Basically, I need re-arrange @P_array and put into sub array, to each sub
array, I exam if at least one element pass a threshold, then I sign the
flag = 1, otherwise flag = 0 in that sub array.
Instead of signing dynamic name for a sub array, I change to use anonymous
array, it works fine. Alternatively, John and Mumia
approach are also works well. Any suggestion for better coding?
Thanks all,
Shiping
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254 968-8328
Don't tread on my bandwidth. Trim your posts.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>