> -----Original Message----- > From: Rob Dixon [mailto:[EMAIL PROTECTED] > Sent: Monday, January 14, 2008 8:59 PM > To: beginners@perl.org > Cc: Kevin Viel > Subject: Re: references to complex data structures > > Kevin Viel wrote: > > Consider the following anonymous array of anonymous arrays: > > > > my $a = [ [ 00 , 01 ] > > , [ 10 , 11 ] > > ] ; > > > > I can print the first element of the first anonymous array: > > > > print "$$a[ 0 ][ 0 ]\n" ; > > > > or, equivalently, I can explicit use bracers to dereference it: > > > > print "${$a}[ 0 ][ 0 ]\n" ; > > OK > > But they're 'braces' :) > > > Should I not need two pairs of bracers? > > The 'missing' pair of braces is because you're using both of > the two different syntaxes for indexing a referenced array. > The first element of the outer array is either > > ${$a}[0] (which can be written $$a[0] without ambiguity) > > or > > $a->[0] > > These are references to the first inner array, which can also > be indexed in either way. So we have four ways of reaching > the first element of the first inner array: > > ${${$a}[0]}[0] > > ${$a}[0]->[0] > > ${$a->[0]}[0] > > $a->[0]->[0] > > In addition, Perl allows us to remove the arrow operator > between pairs of closing and opening brackets or braces - ][ > or }{, so the second and last options can be written > > ${$a}[0][0] > > $a->[0][0] > > and so your code turns out to be the same as the first of > these two. If you use the same syntax for indexing in both > cases then the second pair of braces reappears. It is also > the same as your final example below. > > > $a is a reference to the anonymous array. The elements of the > > anonymous arrays are references to anonymous arrays, correct? > > They are references to arrays, yes. They may be named arrays > or anonymous ones. > > > The following seems to achieve this result: > > > > print "${${$a}[ 0 ]}[ 0 ]\n" ; > > > > Is the outmost pair of bracers with the appropriate symbol > ($, @, %) > > the default? If so, how does perl select the correct symbol? > > I'm not sure what you mean here: you have explicit dollar > signs in this code for both dereferences. Perl has no default > way of handling references, but it will complain if you try > to use a reference to one type of data as something different. > > > I realize that it is seemingly moot, but it may help my > understanding > > of more complex structures, like hash of arrays or hash of hases. > > Don't get to like them to the extent that you use them when > your data isn't shaped that way. They are a way of expressing > hierarchical data only.
Thanks for another informative post. My data are hierarchical. I have 22 files, one for each autosome (non-sex chromosome, sex chromosomes being the X and Y-apologies is this is unnecessary to state). In each file I have markers and their locations. The first thing I want to do is to be sure that that a marker is unique to a chromosome: if ( exists $marker_hash{ $marker } ) { print "Collision: Chromosome: $Chr Marker: $marker\n" ; } else{ $marker_hash{ $marker } = $chr ; } However, I would also like to do two things: collect the chromosomes on which a markers exists and create a ordered database table that reports the chromosome , marker , and location. The outer most object would be a hash, the keys of which are the markers. The values of this hash could be a hash with keys being chromosome and the values being an array of locations. Coding aside, through which I still must suffer, does a complex data structure seem appropriate to this problem or should I be considerng another approach? Kind regards, Kevin Kevin Viel, PhD Post-doctoral fellow Department of Genetics Southwest Foundation for Biomedical Research San Antonio, TX 78227 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/