home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewse!budnick
- From: budnick@cbnewse.cb.att.com (Mary Jo Budnick)
- Subject: emulating mulit-dimentional arrays?
- Organization: AT&T
- Distribution: usa
- Date: Wed, 9 Sep 1992 16:33:29 GMT
- Message-ID: <1992Sep9.163329.12565@cbnewse.cb.att.com>
- Lines: 53
-
- Hi,
-
- I see there are no multi-dimensional arrays in Perl; however,
- they can be emulated w/ join and "$;". So, say I want to keep
- track of "time" specific to a name and a counter:
-
- $name = foo;
- $index = 0;
- $time{$name, $index} = "11:00:00";
-
- $name = foo;
- $index = 1;
- $time{$name, $index} = "11:27:15";
-
- $name = goo;
- $index = 0;
- $time{$name, $index} = "12:00:27";
-
- $name = goo;
- $index = 1;
- $time{$name, $index} = "12:30:00";
-
-
- Now, how do I later retrieve all of the names and process all of
- the times for that name?
-
- If I do:
-
- foreach $i (keys(%time)) {
- print "key = $i, time = $time{$key}\n";
- }
-
-
- I get:
-
- key = foo1
- key = goo1
- key = foo0
- key = goo0
-
-
- What I want to do is get "foo" and then get all of the times for
- foo, indexed by 0,1, . . . Then I want to get "goo" and get
- the times for it indexed by 0,1,. . . I don't know the total
- number of names or what they are. I don't know the total
- number of times (indices) for each name.
-
- Any hints?
-
- Thanks,
-
- MJ
-
-