SPUG: QOTW restarted -- #16 currently running
Michael R. Wolf
MichaelRWolf at att.net
Thu May 13 10:39:41 CDT 2004
Perl Quiz-of-the-Week #16 is out, after a long hiatus.
Get more information:
http://perl.plover.com/qotw/
Here's the body of the quiz.
IMPORTANT: Please do not post solutions, hints, or other spoilers
until at least 60 hours after the date of this message.
Thanks.
IMPORTANTE: Por favor, no enviéis soluciones, pistas, o cualquier otra
cosa que pueda echar a perder la resolución del problema hasta
que hayan pasado por lo menos 60 horas desde el envío de este
mensaje. Gracias.
IMPORTANT: S'il vous plaît, attendez au minimum 60 heures après la
date de ce message avant de poster solutions, indices ou autres
révélations. Merci.
WICHTIG: Bitte schicken Sie keine Lösungen, Tipps oder Hinweise für
diese Aufgabe vor Ablauf von 60 Stunden nach dem Datum dieser
Mail. Danke.
BELANGRIJK: Stuur aub geen oplossingen, hints of andere tips in de
eerste 60 uur na het verzendingstijdstip van dit
bericht. Waarvoor dank.
VNIMANIE: Pozhalujsta ne shlite reshenija, nameki na reshenija, i
voobshe lyubye podskazki v techenie po krajnej mere 60 chasov
ot daty etogo soobshenija. Spasibo.
Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60
Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4
Xie4Lou4 Da2An4 De5 Jian4Yi4. Xie4Xie4.
----------------------------------------------------------------
This quiz is phrased for Unix systems. If it makes sense to write a
solution for Windows or other systems, feel free to do so.
The usual way to look for a character string in files in Unix is to use
grep. For instance, let's say you want to search for the word 'summary'
without regard to case in all files in a certain directory. You might say:
grep -i summary *
But if there is a very large number of files in your directory, you will
get something like this:
ksh: /usr/bin/grep: arg list too long
Now, you could just issue multiple commands, like this:
grep -i summary [A-B]*
grep -i summary [C-E]*
etc.
... but that's so tedious. Write a Perl program that allows you to search
all files in such a directory with one command.
You're probably wondering:
- Should I use grep? egrep? fgrep? Perl's regex matching?
- Should there be an option to make the search case-sensitive or not?
- Should we traverse all files under all subdirectories?
You can decide for yourself on these questions. There is one other
requirement, though: the program must not fail when it finds things for
which grepping does not make sense (e.g. directories or named pipes).
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list