4 ms·
I don't totally understand it, but I was impressed by Ward Cunningham's use of awk to calculate who owes who after a vacation, http://c2.com/doc/expense/ http:/
by combatentropy 6y ago
I don't totally understand it, but I was impressed by Ward Cunningham's use of awk to calculate who owes who after a vacation, http://c2.com/doc/expense/ http://c2.com/doc/expense/
- acqq 6y agoIt‘s really a nice example of what can be achieved when one starts solving a specific problem and solves it by generalizing it to create something like an ad hoc language for that kind of reports. Additional bonus for designing it exactly so that it fits to the concepts which one gets already by design of awk. The author explains the idea: “ The program keeps a running sum that it clears when it sees a blank line (NF==0). Other calculations are performed in place. The first occurrence of a variable name defines it as that sum. Subsequent occurrences become the stored value.” The regexp that defines what the variable name is is simply: /^[A-Z]+[A-Z0-9]*$/ and numbers to sum and variables are always only the first word in the line.