osssss has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear friends, does anybody have experienced writing a script that lets a user maintain a calendar/schedule? actually its part of my final exam, but i need help to start right with it. Thanks Sam

Replies are listed 'Best First'.
Re: A calendar tool (command-line version)
by zentara (Cardinal) on Apr 27, 2008 at 19:42 UTC
    This ought to give you are start. Managing recuring calendar events and check out this code, written by someone else(unknown). All you need to do is figure out a hash, to link dates(as keys), with those days appointments(1..24 hours). So a hash of hashes might do it.

    A GUI calendar with Tk or Gtk2 would be alot easier than commandline. Or by commandline, do you mean "not html or cgi" ?

    If you can use Tk or Gtk2 (GUI's), look at Tk::MiniCalendar or Tk::ChooseDate. GUI's are easier, because you can let the user mouse click on a date from a calendar, pop up an text box, and let him enter the appointment and time. Perl/Gtk2 has a 'Calendar' widget too. See Gtk2 Simple Calendar/ Date Selector

    If you are stuck with a true "commandline" program, you will need to work out a system, where you take user input, prompt for times and text, and do all sorts of prompting and confirming input.

    #!/usr/bin/perl -w use strict; use Date::Calc qw(Calendar); #usage cal monthnum yesr; i.e. cal 8 2002 for AUG2002 #defaults to current month my $month = shift || (localtime(time))[4]+ 1; #numeric for subroutine my $year = shift || (localtime(time))[5] +1900; my @cal = parseCalendar(); my @months = (undef,'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $month = $months[$month]; #change $month to 3-letter abbreviation print "\n$month$year: ",'Mo Tu We Th Fr Sa Su',"\n"; my $i = 1; foreach my $cal_line (@cal) { print " Week",$i++,": "; foreach my $day (@$cal_line) { $day ||= " "; print "$day "; }print "\n"; }print "\n"; exit; ##################################################################### sub parseCalendar { my $cal = Calendar($year, $month); my @cal = split(/\n/, $cal); splice(@cal, 0, 3); # get rid of the first three lines (don't need em) +; my @rv = map{$_ = substr($_, 1, length);[split /\s{4}|\s{2}/];}@cal; return @rv; }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      A GUI calendar ist only easier when others already wrote most of the code. ;-)
        As is true with Perl...... it's easier when others write most of the code, from the interpreter itself, to the various modules. It all depends on how familiar you are with the various modules. :-) Honestly, could you even use Perl if you had to write the interpreter yourself? "We see far because we stand on the shoulders of the giants who preceeded us". (paraphrased quote as usual). :-)

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: A calendar tool (command-line version)
by bradcathey (Prior) on Apr 27, 2008 at 19:33 UTC

    Just a warning, you'll probably not get the easy answer you are looking for here at the Monastery. We like people to help themselves, with an occasional nudge from the good Monks that populate these halls. We don't do homework.

    The defacto question at this point is to ask you to show us what you have done. Where's your code so far? What CPAN modules have you looked at? How experienced of a Perl programmer are you?

    Your application sounds like it could be very intense and require loads of code, tapping CRUD methods and then date and time modules. I'd suggest you flow chart this thing out and then ask very specific questions.

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: A calendar tool (command-line version)
by ww (Archbishop) on Apr 27, 2008 at 19:33 UTC
    Sam:

    One possible form of "help:" Review your class notes and text.

    ++ for labeling, but help on a final exam amounts to anti-help... or implies that your instructor has set a question on the final that's not reasonably answerable with the instruction provided. As a general rule -- subject, of course, to exceptions -- one can hope that the former is the case.

    So the second "help" I'll offer is limited to this: Work it out as pseudo-code first, at which point writing the answer may well be almost trivial.

Re: A calendar tool (command-line version)
by Khen1950fx (Canon) on Apr 27, 2008 at 22:46 UTC
    A good place to start is with the Unix cal command. For example, type in cal -y and it'll return a calendar for the current year. That said, merlyn has written a calendar script emulating cal. You'll need Date::Calc.