jdr@sloth.mlb.semi.harris.com (Jim Ray) (02/21/91)
I would like to build an associative array which in turn points to lists ( one per key ). Something like this: $array{$name} = SOME LIST Where SOME LIST is some array ( list ) of indices into another set of arrays containing relivant record information. This array would be periodically added to while traversing the entire list of people. $name is character string containing NAME I realize this has probably been discussed, but I don't have my PERL book yet. -- Jim Ray Harris Semiconductor Internet: jdr@semi.harris.com PO Box 883 MS 62B-022 Phone: (407) 729-5059 Melbourne, FL 32901
jdr@harris.mlb.semi.harris.com (Jim Ray) (02/21/91)
I would like to build an associative array which in turn points to lists ( one per key ). Something like this: $array{$name} = SOME LIST Where SOME LIST is some array ( list ) of indices into another set of arrays containing relivant record information. This array would be periodically added to while traversing the entire list of people. $name is character string containing NAME I realize this has probably been discussed, but I don't have my PERL book yet. Any information would be helpful.
emv@ox.com (Ed Vielmetti) (02/22/91)
In article <1991Feb21.051208.21101@mlb.semi.harris.com> jdr@sloth.mlb.semi.harris.com (Jim Ray) writes:
I would like to build an associative array which in turn points to
lists ( one per key ).
$array{$name} = SOME LIST
Where SOME LIST is some array ( list ) of indices into another set
of arrays containing relivant record information. This array
would be periodically added to while traversing the entire
list of people.
What I have done for this (without perfect luck yet, I admit) is to
simply make the "SOME LIST" a space-delimited string of indexes. When
you need to get the list out as a list you do a split on it, e.g.
$sets{"csound"} = "1990.03:123.Z 1990.06:105.Z 1991.02:3458.Z" ;
$sets{$name} .= " " . $key ; # add a key
@keys = split(" ",$sets{$name}) ; # get your list back
you'll probably want and, or, xor, sort, and uniq operators on these
things too.
--Ed
allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (02/26/91)
As quoted from <1991Feb21.051208.21101@mlb.semi.harris.com> by jdr@sloth.mlb.semi.harris.com (Jim Ray): +--------------- | I would like to build an associative array which in turn points to | lists ( one per key ). | | $array{$name} = SOME LIST | Where SOME LIST is some array ( list ) of indices into another set | of arrays containing relivant record information. This array | would be periodically added to while traversing the entire | list of people. +--------------- Perl doesn't support it per se; the usual solution is to store it as a string or in other variables and use eval. Me, in my latest abomination (about which more later, I see something about it in a later thread) I found a need for lists of lists. So, with a little hacking, I came up with this monstrosity: $gensym = 'gensym00000000000'; sub pushlist { local(*l1, @l2) = @_; local(*sym) = $gensym++; @sym = @l2; push(@l1, *sym); } sub poplist { local(*l1) = @_; local(*sym) = pop(@l1); @sym; } Similar routines can be written for shift and unshift. ++Brandon -- Me: Brandon S. Allbery VHF/UHF: KB8JRR on 220, 2m, 440 Internet: allbery@NCoast.ORG Packet: KB8JRR @ WA8BXN America OnLine: KB8JRR AMPR: KB8JRR.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery Delphi: ALLBERY