Inspired by this code-golf challenge, I thought it would be easy to achieve the end result with awk. The algorithm would be: convert everything to lowercase, then get only vowels to uppercase.
我以为这样可以
awk '{$0=tolower($0);print gensub(/[aeiou]/,toupper("&"),"g")}'
> HeLlO
> hello
但它所做的只是以小写形式回显输入。然后,我开始摆弄它:
$ awk '{$0=tolower($0);print gensub(/[aeiou]/,"&"toupper("&"),"g")}'
> HeLlO
> heelloo
I was about to conclude that maybe the parser was reading "&""&"
, since awk can be very forgiving at times. But then, I tried with other functions:
$ awk '{$0=tolower($0);print gensub(/[aeiou]/,strtonum("&"),"g")}'
> HeLlO
> h0ll0
因此,总而言之,我缺少什么?
不。Awk不是一种功能编程语言;它不是功能语言。函数的参数将立即求值。
toupper("&")
yields&
back,"&"toupper("&")
evaluates to"&&"
, henceee
andoo
.And
strtonum("&")
returns0
, so you're replacinga
,e
,i
,o
andu
with0
there.