On 09/29/2006 11:49 AM, 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. I have a problem to
dynamically give sub array a name. Any help? Maybe I should use
anonymous array?
Thanks,
Shiping
Here is my code:
use strict;
use warnings;
my @big_arr = (
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);
for (my $i = 0; $i < 10; $i++){
my @q_$i = ($P_array[$i], @P_array[8*$i+10 .. 8*$i+17]);
for (@q_$i){
print join "\t", @_$i, "\n";
}
}
Create an anonymous array and put it into a hash. Read "perldoc perldsc"
E.g.
my %q;
...
$q{$i} = [ ($P_array[$i], @P_array[8*$i+10 .. 8*$i+17]) ];
...
print join("\t", @{$q{$i}}), "\n";
...
WARNING: UNTESTED CODE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>