I apologize for my complex code, but my question does not concern most of it. My problem is putting elements into an array. Right now I have a 3D array of which x->y->z, x points to a list of y's and each y points to a list of 6 values. What I am trying to do is sort just a part of the y list. I need to get y elements out, sort them and then put them back into the big array, in order. Here is my jumbled code. Again, I apologize, but if you could just concentrate on the array assignments and referencing. I am trying to pull out x and y values (that's what
$blocks[$i][$l][1] = x, $blocks[$i][$l][2] = y are. I am trying to find the distance from these points to the solid vertex before it (solid vertex is
$blocks[$i][$k][4] == 88888 I also included a sample of the big array. If
[$i][$j][4] == 88888 then it is a solid vertex. I am trying to sort the points in between these solid vertex. i.e.
[0][2][4] = 0 and
[0][3][4] = 0 so I am trying to sort these two relative to their distance from the first solid vertex
[0][1][4] = 88888 a solid vertex. Any help with the referencing of the arrays would be great. I tried to use the DUmper, but I could not tell where things were. My errors are uninitiated value.
Here is my code
for $k (($j+1)..$#{$blocks[$i]}) {
if ($blocks[$i][$k][4] == 88888) {
my @a;
for $l (($j + 1)..($k - 1)) {
$a[$l][1] = $blocks[$i][$l][1];
$a[$l][2] = $blocks[$i][$l][2];
}
push @aa, \@a;
for my $pp (($j + 1)..($k - 1)) {
print "[$pp][1] => $aa[$pp][1]\n";
print "[$pp][2] => $aa[$pp][2]\n";
}
my @d;
for $m (($j + 1)..($k - 1)) {
my $e3 = $aa[$m][1];
print " $e3\n";
$d[$m][1] = sqrt((($aa[$m][1] - $blocks[$i][$m
+][1])*($aa[$m][1] - $blocks[$i][$m][1])) + (($aa[$m][1] - $blocks[$i]
+[$m][1])*($aa[$m][1] - $blocks[$i][$m][1])));
$d[$m][2] = $m;
}
push @dd, \@d;
my @sortedist = sort { $a -> [1] <=> $b -> [1] } @
+dd;
for $n (($j + 1)..($k - 1)) {
$temp = $blocks[$i][$n];
$blocks[$i][$n] = $blocks[$i][($sortedist[$n][
+2])];
$blocks[$i][($sortedist[$n][2])] = $blocks[$i]
+[$n];
[0][0][0] =>1
[0][0][1] =>515.438792
[0][0][2] =>2167.220067
[0][0][3] =>0
[0][0][4] =>88888
[0][0][5] =>99999
[0][0][6] =>99999
[0][1][0] =>2
[0][1][1] =>535.930414
[0][1][2] =>2240.612915
[0][1][3] =>0
[0][1][4] =>88888
[0][1][5] =>99999
[0][1][6] =>99999
[0][2][0] =>3
[0][2][1] =>1123.073200
[0][2][2] =>2076.679934
[0][2][3] =>0
[0][2][4] =>0
[0][2][5] =>99999
[0][2][6] =>99999
[0][3][0] =>4
[0][3][1] =>1102.581578
[0][3][2] =>2003.287086
[0][3][3] =>0
[0][3][4] =>0
[0][3][5] =>99999
[0][3][6] =>99999
[0][4][0] =>5
[0][4][1] =>515.438792
[0][4][2] =>2167.220067
[0][4][3] =>0
[0][4][4] =>88888
[0][4][5] =>99999
[0][4][6] =>99999
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.