diff options
Diffstat (limited to 'doc/gawk.texi')
-rw-r--r-- | doc/gawk.texi | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/doc/gawk.texi b/doc/gawk.texi index fb71bb68..0372897f 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -23256,7 +23256,7 @@ function shell_quote(s, # parameter @end example @node Isnumeric Function -@subsection Checking whether a value is numeric +@subsection Checking Whether A Value Is Numeric A frequent programming question is how to ascertain whether a value is numeric. This can be solved by using this example function @code{isnumeric()}, which @@ -23271,16 +23271,21 @@ employs the trick of converting a string value to user input by using the function isnumeric(x, f) @{ - switch (typeof(x)) @{ - case "strnum": - case "number": - return 1 - case "string": - return (split(x, f, " ") == 1) && (typeof(f[1]) == "strnum") - default: - return 0 - @} + switch (typeof(x)) @{ + case "strnum": + case "number": + return 1 + case "string": + return (split(x, f, " ") == 1) && (typeof(f[1]) == "strnum") + default: + return 0 + @} @} + +Please note that leading or trailing white space is disregarded in deciding +whether a value is numeric or not, so if it matters to you, you may want +to add an additional check for that. + @c endfile @end example @@ -24155,8 +24160,8 @@ $ @kbd{awk -f getopt.awk -v _getopt_test=1 -- -a \} @print{} c = <otherd>, Optarg = <> @print{} c = <otherc>, Optarg = <> @print{} non-option arguments: -@print{} ARGV[8] = <arg1> -@print{} ARGV[9] = <arg2> +@print{} ARGV[8] = <arg1> +@print{} ARGV[9] = <arg2> @end example In all the runs, the first @option{--} terminates the arguments to @@ -26353,7 +26358,7 @@ look nice on the page: @end ignore @c file eg/prog/split.awk -function usage( common) +function usage( common) @{ common = "[-a suffix-len] [file [outname]]" printf("usage: split [-l count] %s\n", common) > "/dev/stderr" @@ -30186,7 +30191,7 @@ main(void) printf("%d\n", x + y); return 0; @} -$ @kbd{cc -O add.c -o add} @ii{Compile the program} +$ @kbd{cc -O add.c -o add} @ii{Compile the program} @end example You could then write an exceedingly simple @command{gawk} program |