At 08.50 98.01.19, Wade Williams wrote: >I realize this is a bit of a general question, but I thought some here >might have some solutions. > >One of the things I used to love about the Think C debugger was that it >allowed me to figure out complex dereferences. Need to know how a pointer >to a record containing a pointer to an array would look? Just play around >with it in the debugger until you hit on the combination that displays the >proper data. Hmm...*myrec->array[0] doesn't work...maybe it's >(*(myrec->array))[0]....things like that. > >I'm having difficulty understanding how to build and reference complex data >structures in Perl. Now, generally, I'm a pretty bright guy, but the idea >of references just hasn't clicked yet. I've read all the man pages, the >Camelbook, etc, but I'm still struggling. Let's see..should that be >$myarray[0][0], $myarray->[0][0] or @$myarray[0][0]? > >In short, other than trying "print somecombination" until I get the right >data printed, does anyone have any tips for either tools to help you >reference complex structures correctly, or any pointers to any more >tutorial information which can help me get over the hump on the whole >references/complex structures issue. IMO, the best ways to learn about these structures are: * the man pages perlref, perldsc, perllol * the Data::Dumper module An example of Data::Dumper: use Data::Dumper; $a[0][0] = 'b'; $i->[0][0] = 'j'; $m[0]->[0] = 'n'; $x->[0]->[0] = 'y'; print Dumper \@a, $i, \@m, $x; But personally, I like to construct my data structures like this so I can see what is going on: @a = (['b']); $i = [['j']]; @m = (['n']); $x = [['y']]; If you use these statements instead of the others, you might notice that the print statement still prints the same thing. Just remember that [0..10] is an anonymous reference to an array, {a=>1} is an anonymous reference to a hash. $pets = {Dogs=>['Banjo','Opie','Tubb'], Cats=>['Fester']}; Have fun, -- Chris Nandor pudge@pobox.com http://pudge.net/ %PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6']) #== MacPerl: Power and Ease ==# #== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==# ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch