Groups | Search | Server Info | Login | Register


Groups > alt.comp.lang.awk > #1

Is it possible to convert strings to math operators?

From someone <someone@invalid.invalid>
Newsgroups alt.comp.lang.awk
Subject Is it possible to convert strings to math operators?
Date 2023-02-15 13:35 -0700
Organization Ministry of Madness
Message-ID <tsjflq$8ni$1@nnrp.usenet.blueworldhosting.com> (permalink)

Show all headers | View raw


I didn't see anything in the gawk(1) manpage for doing this but it seems 
like it should be possible.

ex.  oz to lb using old-school units(1) command:
--
$ units -1 oz lb
    * 0.0625

# this works:
$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 * $3 " lb"}'
16 oz = 1 lb

# this does NOT work:
$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 $2 $3 " lb"}'
16 oz = 16*0.0625 lb

--

Is there a way to tell (g)awk to interpret strings like "*", "/", "+", 
"-", etc. as actual math operators?

Back to alt.comp.lang.awk | Next | Find similar


Thread

Is it possible to convert strings to math operators? someone <someone@invalid.invalid> - 2023-02-15 13:35 -0700

csiph-web