home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!swrinde!gatech!concert!sas!mozart.unx.sas.com!sasswb
- From: sasswb@unx.sas.com (Scott Bass)
- Subject: Multi-dimensional arrays
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <sasswb.722021479@k2>
- Date: Tue, 17 Nov 1992 17:31:19 GMT
- Nntp-Posting-Host: k2.unx.sas.com
- Organization: SAS Institute Inc.
- Lines: 51
-
- I've got the Perl (Camel) book and have read it cover to cover, but I don't
- remember it covering the above subject (I admit I haven't dug around in it
- for this specific subject).
-
- Sooooo . . .
-
- 1. How can I code a multi-dimensional array in perl, say an Nx5 array?
-
- 2. Can I do this with an associative array, i.e. have the key for the
- associative array determine the row of the array?
-
- 3. Can I load the array via a here document or lines after a __DATA__
- token, i.e. from a "file"?
-
- What I'm trying to do is set variables based on some command line
- parameters. I'd like to have an easy-to-maintain lookup table that sets
- values based on command line switches. In rather poor pseudo-code:
-
- @array = <<EOF
- 'foo','parm1','parm2','parm3','parm4','parm5'
- 'bar','parma','parmb','parmc','parmd','parme'
- EOF
-
- where 'foo' and 'bar' are keys to the associative array. Then:
-
- while (shift) {
- p1 = $array($_,1);
- p2 = $array($_,2);
- p3 = $array($_,3);
- p4 = $array($_,4);
- p5 = $array($_,5);
- }
-
- or something like that. I could probably optimize it further by using a
- loop inside the while, but the above would get me started.
-
- In summary, I want a single keyword command line parameter to trigger
- several other options. I want to maintain the relationships in a table
- somewhere so I can just add or delete rows from the table to add new
- command line switches, rather than digging thru the code adding logic.
- Seems like NxM arrays would do the trick, but don't know how to code them.
-
- In case it's not obvious, I'm new at perl (but really like it!!!)
-
- Thanks for any help you can give.
-
- ------------------------------------------------------------------------------
- Scott Bass | SAS Institute Inc.
- Integrated Systems, A216, x6975 | SAS Campus Drive, Cary, NC 27513-2414
- sasswb@k2.unx.sas.com | (919) 677-8001 x6975
- ------------------------------------------------------------------------------
-