RosettaCodeData/Task/Menu/AWK/menu.awk

25 lines
502 B
Awk
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
# syntax: GAWK -f MENU.AWK
BEGIN {
2019-09-12 10:33:56 -07:00
print("you picked:",menu(""))
print("you picked:",menu("fee fie:huff and puff:mirror mirror:tick tock"))
exit(0)
}
function menu(str, ans,arr,i,n) {
if (str == "") {
return
}
n = split(str,arr,":")
2013-04-10 21:29:02 -07:00
while (1) {
print("")
for (i=1; i<=n; i++) {
printf("%d - %s\n",i,arr[i])
}
2019-09-12 10:33:56 -07:00
printf("? ")
2013-04-10 21:29:02 -07:00
getline ans
if (ans in arr) {
2019-09-12 10:33:56 -07:00
return(arr[ans])
2013-04-10 21:29:02 -07:00
}
print("invalid choice")
}
}