home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7024 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.3 KB  |  63 lines

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