Previous: Library Functions Summary, Up: Library Functions   [Contents][Index]

10.9 Exercises

  1. In Empty Files, we presented the zerofile.awk program, which made use of gawk’s ARGIND variable. Can this problem be solved without relying on ARGIND? If so, how?
  2. As a related challenge, revise that code to handle the case where an intervening value in ARGV is a variable assignment.
  3. Walking Arrays, presented a function that walked a multidimensional array to print it out. However, walking an array and processing each element is a general-purpose operation. Generalize the walk_array() function by adding an additional parameter named process.

    Then, inside the loop, instead of printing the array element’s index and value, use the indirect function call syntax (see Indirect Calls) on process, passing it the index and the value.

    When calling walk_array(), you would pass the name of a user-defined function that expects to receive an index and a value, and then processes the element.

    Test your new version by printing the array; you should end up with output identical to that of the original version.