7 my $reminders = "$ENV{HOME}/reminders/stuff";
9 my $argstring = join (" ", @ARGV);
10 my ($when, $what, $howmany);
12 (undef, $when, undef, $what, $howmany) = ($argstring =~ /^(on |)(.*?) (to|about the|about) (.*?)( for (\d+) days|)$/);
13 if ( $when =~ /^after/ ) {
14 # check for the "after n days" format.
15 # There are better ways of handling multiple regexes, but we'll do
16 # things this way since there are only two for now.
19 ($when, $unit, undef, $what, $howmany) =
20 ($argstring =~ /^after (\d+) (days|weeks|months|business days) (to|about the|about) (.*?)( for (\d+) days|)$/);
22 $when = DateCalc
("today", "+$when $unit");
25 quit
("what?") unless $what;
26 quit
("when?") unless $when;
28 if( $howmany =~ /(\d+)/ ) {
35 # form the line to be appended
36 my $date = ParseDate
($when);
37 quit
("cannot parse date") unless $date;
39 my $line = UnixDate
($date, "REM %b %e %Y $howmany MSG");
40 $line .= " $what %b.%\n";
45 open LOCK
, ">$reminders.lock" or quit
("cannot open $reminders.lock : $!");
46 flock LOCK
, LOCK_EX
or quit
("cannot obtain lock : $!");
48 # open data file, write and close data file
49 open REMINDERS
, ">>$reminders" or quit
("cannot open $reminders : $!");
50 print REMINDERS
$line;
62 print STDERR
$msg, "\n";