0: This probably doesn't present much of a challenge, but I thought I'd post
1: it since it's the first time I've ever really grokked Perl golf.
2:
3: A coworker (non-programmer) has been taking a course in C and asked me to
4: help out with a program that takes a list of names through input, and
5: print them back out when finished. Since I don't know C, I thought I'd
6: show her how it could be done in Perl. Then something weird clicked in
7: my brain, and I began shaving my original script down, character by
8: character, from 201 characters (formatted and commented) to 77.
9:
10: My version takes a list of names in 'first m last' (e.g. "Larry J Wall")
11: format, and appends the name to a file in 'last first m' format.
12: The script ends when it does not receive input in the correct format.
13:
14: Here's what I came up with...
15:
16:
17: #!/usr/bin/perl
18:
19: open(N,">>names");while(<>){last if!/(\w+) (\w) (\w+)/;print N"$3\t$1\t$2\n"}
20:
21:
22: It can be brought down to 71 characters by shortening the filename
23: and replacing the tabs with spaces, but I thought I'd go for an output
24: with a tad bit of formatting. :)
25:
26: joecamel In reply to A first one-liner by joecamel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |