awk and Perl (was Re: How to print last <n> pages of a file?)
Brian Rice
rice at groupw.rtp.dg.com
Fri May 3 12:04:29 AEST 1991
:-<words>
That is a picture of a person (me) eating his words.
In the referred-to posting, a Perl aficionado gives a Perl solution
to a problem (printing the last n pages of a file), along with a
perfectly gracious plug for Perl. Now, for assorted ungracious
reasons, I have not been in the Perl camp; I felt that...
(a) Perl code is too cryptic;
(b) One can write a solution to any old problem using
standard tools in less time than it takes to retrieve
and compile Perl; and
(c) Perl, being a kitchen-sink kinda thing, is just sorta
inelegant.
So when I saw the Perl posting, I thought, "Hah! I'll just knock
off a solution using awk...won't take a second, especially given
awk's capacity to use a given character other than space as a
field separator."
Well, that was some time ago. Quite some time ago indeed.
There goes (b). I'm giving up; it's pretty tricky. If you'd like
to try, remember that you have to deal with input files like this:
This is page 1.
More text on page 1.
^L
This is page 2.
^LThis is page 3.^L
^LThis is page 5 (yes, I do mean 5).
More text on page 5.^LThis is page 6.
More text on page 6.^LThis is page 7.^L
^LThis is page 9.^LThis is page 10.^L
My code is a rat's nest, and it's looking like it'll get uglier
the closer it gets to being correct (not that it's going to
get any closer). Bye-bye, (a). And it occurred to me
as I was toiling that awk is kind of a kitchen-sink thing too,
except we're used to it. Bye-bye, (c). If anyone has an awk
solution which can handle the above text file and is elegant
and clearly understood, I'd like to see it. Yer a tougher
dude than I. (Don't forget to handle the case where you go
to a new page because you had more than 65 lines on the previous
one; admittedly, that's the easy part, but we gotta be
complete. And the Perl poster seems to have forgotten
that case in his [admittedly justifiable] enthusiasm :-).)
So maybe I'll be learning Perl soon. But I do have one final
malediction: I really think that the public competitions we've
seen among Perl devotees to find maximally compact solutions
to coding problems are ill-advised because (if you'll pardon
the overweening moralism) they set a bad example for new
programmers. There's nothing like time spent maintaining
other people's code to change yer perspective on that sort
of high-jinks... But I'm just a killjoy, anyway. Have fun,
y'all.
--
Brian Rice rice at dg-rtp.dg.com +1 919 248-6328
DG/UX Product Assurance Engineering
Data General Corp., Research Triangle Park, N.C.
"Boy, I hope those dogs eat that cat." --Tula, age 3
More information about the Comp.unix.questions
mailing list