sub() 関数内で関数呼び出し
http://d.hatena.ne.jp/jiangmin-alt/20050905
↑のところで、s/pattern/replacement/ の replacement に関数を呼び出せるそうであると知ってしまった。
Perl で、しかも 1 ファイルで動作する軽量 Wiki の wifky のソースを見てみると、
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
なんてくだりが確かにありました。
で、awk で使えるのか? と思って (良い例ではないものの) ちょろっとだけ試してみました。
gawk '{sub(/END/,sin(NR));print}' wifky.pl (中略) __-0.773948__ <!-- generated by wifky -->
へ〜、って驚いたついでに man page を見てみた。
gsub(r, s [, t]) For each substring matching the regular expression r in the string t, substitute the string s, and return the number of substitutions. If t is not supplied, use $0. An & in the replacement text is replaced with the text that was actu- ally matched. Use \& to get a literal &. (This must be typed as "\\&"; see GAWK: Effective AWK Programming for a fuller discussion of the rules for &'s and backslashes in the replacement text of sub(), gsub(), and gensub().)
特に関数が使えるとも書かれていない。
info で確認したものの、それらしき表現がない。ソースで見た感じだと、結果的に許可されているような感じに見受けられるのですが・・・。
経典の中にも見受けられない。ちと保留。