home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5796 < prev    next >
Encoding:
Text File  |  1992-09-09  |  1.5 KB  |  64 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewse!budnick
  3. From: budnick@cbnewse.cb.att.com (Mary Jo Budnick)
  4. Subject: emulating mulit-dimentional arrays?
  5. Organization: AT&T
  6. Distribution: usa
  7. Date: Wed, 9 Sep 1992 16:33:29 GMT
  8. Message-ID: <1992Sep9.163329.12565@cbnewse.cb.att.com>
  9. Lines: 53
  10.  
  11. Hi,
  12.  
  13. I see there are no multi-dimensional arrays in Perl; however,
  14. they can be emulated w/ join and "$;".  So, say I want to keep
  15. track of "time" specific to a name and a counter:
  16.  
  17.         $name = foo;
  18.         $index = 0;
  19.         $time{$name, $index} = "11:00:00";
  20.  
  21.         $name = foo;
  22.         $index = 1;
  23.         $time{$name, $index} = "11:27:15";
  24.  
  25.         $name = goo;
  26.         $index = 0;
  27.         $time{$name, $index} = "12:00:27";
  28.  
  29.         $name = goo;
  30.         $index = 1;
  31.         $time{$name, $index} = "12:30:00";
  32.  
  33.  
  34. Now, how do I later retrieve all of the names and process all of
  35. the times for that name?
  36.  
  37. If I do:
  38.  
  39.         foreach $i (keys(%time)) {
  40.                 print "key = $i, time = $time{$key}\n";
  41.         }
  42.  
  43.  
  44. I get:
  45.  
  46.         key = foo1
  47.         key = goo1
  48.         key = foo0
  49.         key = goo0
  50.  
  51.  
  52. What I want to do is get "foo" and then get all of the times for
  53. foo, indexed by 0,1, . . .  Then I want to get "goo" and get
  54. the times for it indexed by 0,1,. . .  I don't know the total
  55. number of names or what they are.  I don't know the total
  56. number of times (indices) for each name.
  57.  
  58. Any hints?
  59.  
  60. Thanks,
  61.  
  62. MJ
  63.  
  64.