<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2657.73">
<TITLE>Perl Quiz-of-the-Week #22</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>IMPORTANT: Please do not post solutions, hints, or other spoilers</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; until at least 60 hours after the date of this message.</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks.</FONT>
</P>

<P><FONT SIZE=2>Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Xie4Lou4 Da2An4 De5 Jian4Yi4.&nbsp; Xie4Xie4.</FONT>
</P>

<P><FONT SIZE=2>----------------------------------------------------------------</FONT>
</P>

<P><FONT SIZE=2>The purpose of this problem is very simple (and hopefully something many of us will be able to use).</FONT>
</P>

<P><FONT SIZE=2>Inside a directory (say $ENV{HOME}/.upcoming) we have several files.</FONT>
<BR><FONT SIZE=2>Here's part of one:</FONT>
</P>

<P><FONT SIZE=2>02/26&nbsp;&nbsp; lon brocard</FONT>
<BR><FONT SIZE=2>03/06&nbsp; michelangelo</FONT>
<BR><FONT SIZE=2>05/29&nbsp;&nbsp; simon cozens</FONT>
<BR><FONT SIZE=2>12/28&nbsp;&nbsp; randal schwartz</FONT>
<BR><FONT SIZE=2>02/27 eduardo nuno</FONT>
<BR><FONT SIZE=2>03/05 crapulenza tetrazzini</FONT>
<BR><FONT SIZE=2>03/16 richard m. stallman </FONT>
</P>
<BR>

<P><FONT SIZE=2>This particular file is appropriately named 'birthdays'. You can have as many different files as you wish in that directory.</FONT></P>

<P><FONT SIZE=2>Here's part of another file, 'events':</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp; 01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; payday</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; 15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; payday</FONT>
<BR><FONT SIZE=2>08/13/2004&nbsp; slides for YAPC::EU::2004</FONT>
<BR><FONT SIZE=2>03/01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; feast of st. david</FONT>
<BR><FONT SIZE=2>03/01/1565&nbsp; Rio de Janeiro founded&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>03/09/2004&nbsp; dentist appointment 10:00</FONT>
</P>

<P><FONT SIZE=2>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.&nbsp; The 'events'</FONT></P>

<P><FONT SIZE=2>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.</FONT></P>

<P><FONT SIZE=2>This week's problem consists of writing the script 'upcoming', which tells us about our upcoming events.&nbsp; Suppose today is 26 February.</FONT></P>

<P><FONT SIZE=2>Then the output will contain:</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; birthdays</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ===&gt; 02/26&nbsp;&nbsp; lon brocard</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp; 02/27&nbsp;&nbsp; eduardo nuno</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; events</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp;&nbsp;&nbsp;&nbsp; 03/01&nbsp;&nbsp; payday</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp;&nbsp;&nbsp;&nbsp; 03/01&nbsp;&nbsp; Feast of St. David</FONT>
</P>
<BR>

<P><FONT SIZE=2>Explanation:</FONT>
</P>

<P><FONT SIZE=2>* For each file, you get a paragraph, if there are upcoming events</FONT>
<BR><FONT SIZE=2>&nbsp; mentioned in that file.</FONT>
</P>

<P><FONT SIZE=2>* The program will print all the events that will occur in the next</FONT>
<BR><FONT SIZE=2>&nbsp; 'n' days, where 'n' is specified with a '-n' command-line flag.&nbsp; If</FONT>
<BR><FONT SIZE=2>&nbsp; '-n' is omitted, 'n' will default to 7 days.</FONT>
</P>

<P><FONT SIZE=2>* For each event, you get a string that tells you about the event's proximity:</FONT>
</P>

<P><FONT SIZE=2>&nbsp; 0 =&gt;&nbsp; '&nbsp;&nbsp; ===&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 1 =&gt;&nbsp; '&nbsp;&nbsp; --&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 2 =&gt;&nbsp; '&nbsp; --&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 3 =&gt;&nbsp; ' --&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 4 =&gt;&nbsp; '--&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 5 =&gt;&nbsp; '-&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 6 =&gt;&nbsp; '&gt;',</FONT>
<BR><FONT SIZE=2>&nbsp; 7 =&gt;&nbsp; ' ',</FONT>
</P>

<P><FONT SIZE=2>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.</FONT></P>

<P><FONT SIZE=2>Here we're running the program on 26 February, as before, but with the option '-n 12':</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; birthdays</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ===&gt; 02/26&nbsp;&nbsp; lon brocard</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp; 02/27&nbsp;&nbsp; eduardo nuno</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (8)&nbsp;&nbsp;&nbsp;&nbsp; 03/05&nbsp;&nbsp; crapulenza tetrazzini</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (9)&nbsp;&nbsp;&nbsp;&nbsp; 03/06&nbsp;&nbsp; Michelangelo</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; events</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp;&nbsp;&nbsp;&nbsp; 03/01&nbsp;&nbsp; Feast of St. David</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --&gt;&nbsp;&nbsp;&nbsp;&nbsp; 03/01&nbsp;&nbsp; payday</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (12)&nbsp;&nbsp;&nbsp; 03/09&nbsp;&nbsp; dentist appointment 10:00</FONT>
</P>
<BR>

<P><FONT SIZE=2>Note that the founding of Rio de Janeiro did not occur in either output, since it has already passed.</FONT>
</P>

<P><FONT SIZE=2>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).</FONT></P>

<P><FONT SIZE=2>It might be a good idea to find a reasonable way to solve this.</FONT>
</P>

<P><FONT SIZE=2>Happy hacking :-)</FONT>
</P>

</BODY>
</HTML>