[Neworleans-pm] Fwd: Perl Quiz-of-the-Week #22

E. Strade, B.D. estrabd at yahoo.com
Thu Aug 26 08:19:59 CDT 2004




=====
http://www.brettsbsd.net/~estrabd

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

----- Original message -----
From: "Jose Alves de Castro" <jcastro at telbit.pt>
To: perl-qotw at plover.com
Date: Wed, 25 Aug 2004 23:11:58 -0400
Subject: Perl Quiz-of-the-Week #22


IMPORTANT: Please do not post solutions, hints, or other spoilers
        until at least 60 hours after the date of this message.
        Thanks.

Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60
        Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4
        Xie4Lou4 Da2An4 De5 Jian4Yi4.  Xie4Xie4.

----------------------------------------------------------------

The purpose of this problem is very simple (and hopefully something
many of us will be able to use).

Inside a directory (say $ENV{HOME}/.upcoming) we have several files.
Here's part of one:

02/26   léon brocard
03/06  michelangelo
05/29   simon cozens
12/28   randal schwartz
02/27 eduardo nuno
03/05 crapulenza tetrazzini
03/16 richard m. stallman 


This particular file is appropriately named 'birthdays'. You can have
as many different files as you wish in that directory.

Here's part of another file, 'events':

   01       payday
   15       payday
08/13/2004  slides for YAPC::EU::2004
03/01       feast of st. david
03/01/1565  Rio de Janeiro founded        
03/09/2004  dentist appointment 10:00

As you can see, both the month and the year are optional. When not
given a month, we'll have three spaces; by the end of the date we may
have as many spaces and/or tabs up to the description.  The 'events'
file says that payday occurs on the 1st and 15th of every month, and
that the Feast of St. David occurs each year on the first day of March.

This week's problem consists of writing the script 'upcoming', which
tells us about our upcoming events.  Suppose today is 26 February.
Then the output will contain:

        birthdays
           ===> 02/26      léon brocard
           -->  02/27      eduardo nuno

        events
        -->     03/01   payday
        -->     03/01   Feast of St. David


Explanation:

* For each file, you get a paragraph, if there are upcoming events
  mentioned in that file.

* The program will print all the events that will occur in the next
  'n' days, where 'n' is specified with a '-n' command-line flag.  If
  '-n' is omitted, 'n' will default to 7 days.

* For each event, you get a string that tells you about the event's
proximity:

  0 =>  '   ===>',
  1 =>  '   -->',
  2 =>  '  -->',
  3 =>  ' -->',
  4 =>  '-->',
  5 =>  '->',
  6 =>  '>',
  7 =>  ' ',

If the '-n' switch is given, and the event is in the specified range,
but more then 7 days ahead, then the proximity string is something
like (8) or (13) depending on how many days ahead the event is.
Here we're running the program on 26 February, as before, but with the
option '-n 12':

        birthdays
           ===> 02/26      léon brocard
           -->  02/27      eduardo nuno
        (8)     03/05   crapulenza tetrazzini
        (9)     03/06   Michelangelo

        events
        -->     03/01   Feast of St. David
        -->     03/01   payday
        (12)    03/09   dentist appointment 10:00


Note that the founding of Rio de Janeiro did not occur in either
output, since it has already passed.

As you'll notice, it's a little hard to schedule things such as the
fourth Thursday of each month, or dates like Mother's Day (I don't
know about the rest of the world, but that changes, here in Portugal).
It might be a good idea to find a reasonable way to solve this.

Happy hacking :-)



More information about the NewOrleans-pm mailing list