Server IP : 85.214.239.14 / Your IP : 18.119.255.170 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/share/doc/gawk/examples/prog/ |
Upload File : |
# indirectcall.awk --- Demonstrate indirect function calls # # Arnold Robbins, arnold@skeeve.com, Public Domain # January 2009 # average --- return the average of the values in fields $first - $last function average(first, last, sum, i) { sum = 0; for (i = first; i <= last; i++) sum += $i return sum / (last - first + 1) } # sum --- return the sum of the values in fields $first - $last function sum(first, last, ret, i) { ret = 0; for (i = first; i <= last; i++) ret += $i return ret } # For each record, print the class name and the requested statistics { class_name = $1 gsub(/_/, " ", class_name) # Replace _ with spaces # find start for (i = 1; i <= NF; i++) { if ($i == "data:") { start = i + 1 break } } printf("%s:\n", class_name) for (i = 2; $i != "data:"; i++) { the_function = $i printf("\t%s: <%s>\n", $i, @the_function(start, NF) "") } print "" } # num_lt --- do a numeric less than comparison function num_lt(left, right) { return ((left + 0) < (right + 0)) } # num_ge --- do a numeric greater than or equal to comparison function num_ge(left, right) { return ((left + 0) >= (right + 0)) } # do_sort --- sort the data according to `compare' # and return it as a string function do_sort(first, last, compare, data, i, retval) { delete data for (i = 1; first <= last; first++) { data[i] = $first i++ } quicksort(data, 1, i-1, compare) retval = data[1] for (i = 2; i in data; i++) retval = retval " " data[i] return retval } # sort --- sort the data in ascending order and return it as a string function sort(first, last) { return do_sort(first, last, "num_lt") } # rsort --- sort the data in descending order and return it as a string function rsort(first, last) { return do_sort(first, last, "num_ge") }