home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / perl / 7611 < prev    next >
Encoding:
Internet Message Format  |  1992-12-24  |  2.7 KB

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!male.EBay.Sun.COM!jethro.Corp.Sun.COM!eric.arnold@sun.com
  2. From: eric.arnold@sun.com (eric )
  3. Newsgroups: comp.lang.perl
  4. Subject: actually mnemonic special variable names
  5. Date: 25 Dec 1992 01:18:17 GMT
  6. Organization: Sun Microsystems, Inc.
  7. Lines: 61
  8. Distribution: world
  9. Message-ID: <1hdngpINN216@jethro.Corp.Sun.COM>
  10. Reply-To: eric.arnold@sun.com
  11. NNTP-Posting-Host: animus.corp.sun.com
  12.  
  13. Has anyone already written something that aliases all those special
  14. variables (Camel book:  "You can say one thing for them -- they're
  15. certainly concise.").  For example, the first element of the default
  16. work variable is:
  17.  
  18.         $_[$[]    (obChurchLady: "Well, [pause] isn't that *speeecialll*!")
  19. instead of:
  20.           $WORK[$FIRST_ELEM]
  21. or        $WORK[$F_EL]
  22.  
  23. or another eg.:    $OUTPUT_FIELD_SEPARATOR = "\t";
  24. or        $OFS = "\t";
  25.  
  26.         In these cases, you might have the long and short alias
  27.         for people with difference laconic leanings (or
  28.         annoying alliterative abilities?).
  29.  
  30. This requires something like:  
  31.     *WORK = *_;
  32.     *F_EL = *[;
  33.     *OUTPUT_FIELD_SEPARATOR = *<I can't remember>;
  34.     *OFS = *<I can't remember>;
  35.     
  36. or maybe writing a function call package which references the
  37. special variables directly.
  38.  
  39. I was starting to do this myself, but it seemed like a lot of typing,
  40. and there might already be a set of aliases somewhere that people are
  41. using that are semi-standard (E.g. "OFS" for output field separator.)
  42.  
  43. Also, would such an aliasing scheme work for the local special
  44. variables?  I haven't tested many variables yet to see how they
  45. behave.
  46.  
  47. There are two reasons that I want to do this:  1) because I can't
  48. remember the mnemonics suggested by the camel book that supposedly help
  49. one to associate punctuation and diacritical marks with Perl functions
  50. (they were fun to read, but...), and 2) because it's really hard to
  51. write semi-self-documenting/maintainable code with descriptive symbols
  52. when crucial operations hinge around symbols which look like $, or
  53. $_[$[] .
  54.  
  55.  
  56. -Eric
  57. Eric.Arnold@Sun.COM
  58.  
  59.  
  60. P.S. I won't even suggest, lest I get into trouble, that such aliases be
  61. added to Perl, either in "$NAME" form, or in another associative array,
  62. like "%ENV" or "%SIG", like $BUILTIN{OFS} = "\t"; or $SPEC{OFS} or
  63. $SV{OFS} or etc.
  64.  
  65. This is one of the things about Perl which can't "be done more than one
  66. way".  You have to use these variables, and so your script must take on
  67. their obfuscation (IMHO, they're the yuckiest part of Perl, the rest of
  68. which has been steadily growing on me) even if you are trying to make
  69. it look simple by keeping to C constructs, or using the
  70. conversational-style modifiers, or whatever.  As far as I can tell,
  71. this is one area of Perl where you don't have your choice about economy
  72. of style (sans ubiquitous comments, of course).
  73.  
  74.