newbie would appreciate input examples

Wilson GV (gvw@cs.vu.nl)
Wed, 3 Aug 1994 11:56:59 GMT

I'm an AWK user in the process of converting to Python ('cos Python
seems a lot nicer than either AWK or Perl). I'd be grateful if anyone
has an example of the following types of input around:

1. Given the name of a file containing a bunch of records, each of which
consists of a variable number of tab-separated fields on a single line,
open the file, read the lines one at a time, then close the file:

fp = fopen(filename, "r")
while (not eof(fp)) do
argc, argv = readline(fp)
process(argc, argv)
end while

2. Given a line containing a filename, break it into a directory prefix
(if any), a base name, and a .-suffix (if present):

prefix, name, suffix = read_name()

/home/gvw/foo => /home/gvw foo __
/home/gvw/ => /home/gvw __ __
/home/gvw/foo.b => /home/gvw foo b

If there is an archive of such simple examples (like the photocopied
"gray book" that circulated for Pascal when I was an undergrad) I'd
welcome a pointer to it.

Thanks,

=============================================================
Gregory V. Wilson gvw@cs.vu.nl
As practiced by computer science, the study of programming
is an unholy mixture of mathematics, literary criticism,
and folklore.
- B. A. Sheil, 1981
===========================================================