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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.