In a past paper for an exam I have the question:
Months can be represented in different ways, for example as numbers (1, 2, …, 12), or as three- letter month names (Jan, Feb, …, Dec). Suggest how associative arrays in awk can be used to translate from three-letter month names to month numbers, and vice versa, to translate month numbers to three-letter month names.
So I thought I would use associative arrays in the format say the input of the month is in $1:
number_to_month["Jan"] = 1;
print number_to_month[$1]
しかし、私には、これは連想配列の力をうまく活用していないように見えます。さらに、配列内の各月を手動で初期化する必要があります。
他のオプションは何ですか?