in reply to RE: RE: Many-To-Many Relationship
in thread Many-To-Many Relationship
So what the code does is, loop over the number of elements of @A. (If it has ten, the loop goes from 0 to 9). For each of those indices, the value at that index becomes a key in %First, and the value is the element's index, stored in an anonymous array. We have something like this:$A[$_] -- the element of @A at the current index $First{ $A[$_] } -- the previous line is a key in %First @{ } -- and the associated value is an anonymous array
While we can look something up in @A by its index, we can look up the index in %First if we know the something.Elements of @A: 0 zero 1 one 2 two Elements of %First: zero [ 0 ] one [ 1 ] two [ 2 ]
Oh, and in Perl hashes have something called auto-vivification. If you access a hash key that doesn't exist (and try to put data there), the key will be created. (Useful, once you get used to it.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: RE: Many-To-Many Relationship
by Anonymous Monk on Jun 12, 2000 at 20:09 UTC |