home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10285 < prev    next >
Encoding:
Text File  |  1992-08-21  |  2.8 KB  |  62 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
  3. From: navarra@casbah.acns.nwu.edu (John Navarra)
  4. Subject: Re: Associative arrays in [gn]awk --whynot! (long but interesting)
  5. Message-ID: <1992Aug22.032705.6993@news.acns.nwu.edu>
  6. Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
  7. Organization: Northwestern University, Evanston Illinois.
  8. References: <1992Aug14.173952.12112@mccc.edu> <1992Aug15.021954.27159@news.acns.nwu.edu> <1992Aug21.152622.4819@bnr.ca>
  9. Date: Sat, 22 Aug 1992 03:27:05 GMT
  10. Lines: 50
  11.  
  12. In article <1992Aug21.152622.4819@bnr.ca> christo@bnr.ca writes:
  13. >
  14. >I think you are assuming too much.  As far as I know, associative arrays
  15. >have _never_ been guaranteed to be ordered.  Let me dig out my Awk book by
  16. >A, W, and K, and see what it says (dig dig dig dig)...
  17. >
  18. >  p.51: "  for (variable in array)
  19. >                 statement
  20. >        This loop executes _statement_ with _variable_ set in turn to
  21. >        each different subscript in the array.  The order in which the
  22. >        subscripts are considered in implementation dependent.  Results
  23. >        are unpredictable if new elements are added to the array by
  24.              ^^^^^^^^^^^^^
  25. >        _statement_."
  26. >
  27. >This last quote makes it pretty clear that what you describe is not a
  28. >bug, it's a feature.
  29.  
  30.     Again, let me re-state my assertions:
  31.  
  32.         1) The results are NOT unpredictable. Though they might be
  33.            implementation dependent, I can figure out how the elements
  34.            in an associative array will be printed if given the number
  35.            of elements in an array. Some books would lead you to 
  36.            believe that the output is random -- it is not. It is just
  37.            screwy.
  38.  
  39.         2) I said that gawk only prints out associative arrays in 
  40.            numerical order IF AND ONLY IF the elements in the array
  41.            are in numerical order to begin with. This is contradictory
  42.            or at the very least misleading in some books I have read
  43.            where using gawk, the associative array was printed in 
  44.            numerical order only because the input was in numerical
  45.            order, not because of anything gawk did. Thus, if my elements
  46.            were not in numerical order, gawk would rearrange them when
  47.            output (and again, not in the same order they were read in)
  48.            [ See O'Reilly Sed and Awk book p.191 for more]
  49.  
  50.         3) Nawk, gawk, and awk all print out associative arrays in 
  51.            different screwed ways. Although each is predictable, none
  52.            of them work properly. Obviously, most of you responding
  53.            to this message know that they don't work right -- but know
  54.            also, that they do not work differently. 
  55.          
  56.  
  57. -tms 
  58. -- 
  59. From the Lab of the MaD ScIenTiST:
  60.                     
  61. navarra@casbah.acns.nwu.edu        
  62.