return multiple values from an awk function?
Quote:
> % I know how to write an awk function that returns a single value.
> % Is it possible to return multiple values from an awk function?
> Not really, but for numerics, you can concatenate them together and
> split them out in the caller. For instance
> $0 = sqcb($1)
> square = $1
> cube = $2
> function sqcb(a)
> {
> return a*a " " a*a*a
> }
> If the contents of $0 can't be overwritten, you can assign to a string
> and use split on it.
As Martin Cohen reminds us, arrays are passed by reference
so can be used to pass values back from functions, which,
now he mentions it, is used in my own scripts but in general
it seems an odd thing to do. If the OP does this, then probably
the thing to actually *return* is the number of array elements
(where a negative return can indicate an error).
Each day I run a few dozen awk programs over hundreds
of megabytes of data but there are only a couple of functions
which do this. Certainly the idea of a combined cube/square
function seems contrived, but perhaps the OP was merely
using it as an artificial example.
John.