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

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]; }
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.

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

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"; } } }
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



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