awk awk awk

Arrays 3

Other Ways to Display Arrays

We've seen 2 ways to sort an array using asort, asorti but there are several more ways to sort an array using predefined array scanning orders.

Using the array from the previous page:

BEGIN {
	print "Using PROCINFO ...\n"
	awry["three"] = "blueberry"
	awry["two"] = "cherry"
	awry["seven"] = "pineapple"
	awry["eight"] = "orange"
	awry["five"] = "grape"
	awry["six"] = "strawberry"
	awry["four"] = "apple"
	awry["1"] = "pear"
	PROCINFO["sorted_in"] = "@ind_str_asc"
	print "\nSorted by index in ascending order ...";
	for (i in awry) {
		print i " : " awry[i]
	}

This is the same as the previous method.

The key line is
PROCINFO["sorted_in"] = "@ind_str_asc"

@ind_str_asc is the argument to the built-in variable PROCINFO

Think of that as index string ascending

Here is a list of all the 'arguments' you can use with PROCINFO:


All numeric values come before all string values

That is a LOT of control available!

Observant readers will also want to know what subarrays are.

< | Functions 1