[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] Why strings extracted by match() can be considered as numbers
From: |
Peng Yu |
Subject: |
[bug-gawk] Why strings extracted by match() can be considered as numbers? |
Date: |
Mon, 11 Jun 2018 12:40:26 -0500 |
The following example shows that strings extracted by match() can be
considered as numbers. This automatic conversion is not natural to me.
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
seq 10 | awk -e 'BEGIN { match("8", /([0-9]+)/, a) } $1 > a[1] { print }'
seq 10 | awk -e 'BEGIN { a[1] = "8" } $1 > a[1] { print }'
$ ./main.sh
seq 10 | awk -e 'BEGIN { match("8", /([0-9]+)/, a) } $1 > a[1] { print }'
9
10
seq 10 | awk -e 'BEGIN { a[1] = "8" } $1 > a[1] { print }'
9
Based on the manpage, it seems that the results should only be
considered as strings. Why there is such a discrepancy? Thanks.
match(s, r [, a]) Return the position in s where the
regular expression r occurs, or zero if r is not
present, and set the values of
RSTART and RLENGTH. Note that the argument order is the
same as for the ~ operator: str ~ re.
If array a is provided, a is cleared and then ele-
ments 1 through n are filled with the
portions of s that match the corresponding parenthe-
sized subexpression in r. The zero'th
element of a contains the portion of s matched by
the entire regular expression r.
Subscripts a[n, "start"], and a[n, "length"] provide the
starting index in the string and length
respectively, of each matching substring.
--
Regards,
Peng
- [bug-gawk] Why strings extracted by match() can be considered as numbers?,
Peng Yu <=