Hi,
Its no wonder you are confused. The code you are using is extremely clumsy. I say this with no disrespect, but you need to learn to simplify your code. I took everything that you posted and making a few assumptions (is $temp1 supposed to be used each time?) factored it down to
Which to be honest doesnt tell me that much, but at least I can see through the derefrencing and understand what is going on. @bocks appears to be an AoAoA. $rr is an iterator (but what for?), what $jj and $kk are is not clear. @t is a six element list of numbers. Why you want to do the above operations is not at clear, and since the code seems to have basic errors its hard to tell what you are trying to do.my $dp=$datapoint[$kk]; my @t=(11111,$dp->[1],$dp->[2],0,0,99999,1111); $blocks_dp3=$blocks[$dp->[3]]; for my $rr ( ($jj + 1)..$#$blocks_dp3 ) { for my $t (0..$#t) { #swap em? ($blocks_dp3->[$rr][$t],$t[$t])=($t[$t],$blocks_dp3->[$rr][$t] +); } } for my $t (0..$#t) { $blocks_dp3[@$blocks_dp3][$t] = $t[$t]; }
Since you seem to be working with an AoAoA howabout some code to show you how to walk the whole lot and print them out. You used X,Y,Z so ill use that here
In this code its reasonably clear that $ix is the index into @$x, $iy is the index of @$y and so forth. You should be able to use this as a guide to simplying your code and clarifying what you really want to do.use strict; use warnings; my $x=[ [ [1..6],[1..6] ], [ [2..7],[2..7] ], [ [3..8],[3..8] ] ]; print "($x) has ".scalar(@$x)." elements\n"; foreach my $ix (0..$#$x) { my $y=$x->[$ix]; print "\t\$x->[$ix] ($y) has ".scalar(@$y)." elements\n"; foreach my $iy (0..$#$y) { my $z=$y->[$iy]; print "\t\t\$x->[$ix][$iy] ($z) has ".scalar(@$z)." elements\n +"; foreach my $iz (0..$#$z) { print "\t\t\t\$x->[$ix][$iy][$iz] = $z->[$iz]\n"; } } }
Also a guide to you is to useData::Dumper; As much as possible. Whenever you are debugging use it. Although for clearly visualizing simpler (non cyclic) data structures you may prefer one of the other dumpers, perhaps Data::PrettySimple or Data::Dump as their output is little easier to read. The ability to see in perl code what your data looks like is a wonderful development and learning tool.
Anyway, I hope this helps,
--- demerphq
my friends call me, usually because I'm late....
Update: Nice one to chromatic, I started this post and then wandered a way for a while so I didnt see his more elegant simplification. Either way, when two people suggest more or less the same thing its probably worth thinking about :-)
In reply to Re: Hash or not?
by demerphq
in thread Hash or not?
by stu96art
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |