gawk: Nondecimal Data

1 
1 12.1 Allowing Nondecimal Input Data
1 ===================================
1 
1 If you run 'gawk' with the '--non-decimal-data' option, you can have
1 nondecimal values in your input data:
1 
1      $ echo 0123 123 0x123 |
1      > gawk --non-decimal-data '{ printf "%d, %d, %d\n", $1, $2, $3 }'
1      -| 83, 123, 291
1 
1    For this feature to work, write your program so that 'gawk' treats
1 your data as numeric:
1 
1      $ echo 0123 123 0x123 | gawk '{ print $1, $2, $3 }'
1      -| 0123 123 0x123
1 
1 The 'print' statement treats its expressions as strings.  Although the
1 fields can act as numbers when necessary, they are still strings, so
1 'print' does not try to treat them numerically.  You need to add zero to
1 a field to force it to be treated as a number.  For example:
1 
1      $ echo 0123 123 0x123 | gawk --non-decimal-data '
1      > { print $1, $2, $3
1      >   print $1 + 0, $2 + 0, $3 + 0 }'
1      -| 0123 123 0x123
1      -| 83 123 291
1 
1    Because it is common to have decimal data with leading zeros, and
1 because using this facility could lead to surprising results, the
1 default is to leave it disabled.  If you want it, you must explicitly
1 request it.
1 
1      CAUTION: _Use of this option is not recommended._  It can break old
1      programs very badly.  Instead, use the 'strtonum()' function to
1      convert your data (⇒String Functions).  This makes your
1      programs easier to write and easier to read, and leads to less
1      surprising results.
1 
1      This option may disappear in a future version of 'gawk'.
1