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