Welcome to the Monastery | |
PerlMonks |
two-dimensional arraysby Ras (Acolyte) |
on Aug 08, 2001 at 18:14 UTC ( [id://103049]=perlquestion: print w/replies, xml ) | Need Help?? |
Ras has asked for the wisdom of the Perl Monks concerning the following question:
Hi everybody, i really need help in using two d arrays. What i'm trying to do is that i have this arry full of file names. for example @array $array[0] contains eph11.lg $array[1] contains eph21.lg $array[2] contains ehp23.lg $array[3] contains eph31.lg $array[4] contains eph65.lg $array[6] contains eph33.lg $array[7] contains eph66.lg $array[8] contains eph76.lg $array[9] contains eph88.lg . . . It goes on for a while If i try and process these file going from the fisrt index to the last it will take a very long time. So what i want to do is group a certain a mount of files together and process them as a group. The way i group the files is that in a loop i mod the index of @array with the lenght of @array and then push that element into a 2d array with the index of the mod value. For exampel: The index ---0-------1------2------3------4--- ---5-------6------7------8------9--- |files1||file2||file3||file4||file5|| file6||file7||file8||file9||file10| The 2d array: @2darray The length + 1 = 10 10%0=0 so put file1 into $2darray[0][0] 10%1=0 so put file2 into $2darray[0][1] 10%2=0 so put file3 into $2darray[0][2] 10%3=1 so put file4 into $2darray[1][0] 10%4=2 so put file5 into $2darray[2][0] 10%5=0 so put file6 into $2darray[0][3] 10%6=4 so put file7 into $2darray[4][0] 10%7=3 so put file8 into $2darray[3][0] 10%8=2 so put file9 into $2darray[2][1] 10%9=1 so put file1 into $2darray[1][1] 10%10=0 so put file1 into $2darray[0][4] My problem is that i don't know how to do this in perl. What i'm donig, which doesn't work is: for($psh_lp=0;$psh_lp<=$len;$psh_lp){ $mod_val = $psh_lp % $len; push(@group_ary[$mod_val][$phs_lp],$files[$psh_lp]); }</code> Can you show me some kind of snytax that can help me out, thanks in advance.
Back to
Seekers of Perl Wisdom
|
|