ailie has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Monks. If you'd be willing to lend me some of your time and expertise I would appreciate it.
I'm a newcomer to Perl, at the stage where I'm trying to take some of the stuff I've learned from lessons in books and put it into my own little programs. I thought that the diary program (below) would be a good place to start.
I had a few critera I wanted to satisfy with this program - I wanted the entry to be written to two files, a large diary file with all the other entries in it, and to a smaller file with just that date's entries in it. I wanted the date and time to appear before the entries in both files, and for kicks I had the weather in my hometown put into the date file.
I'd like some feedback on this program - I'm sure I have bugs, needlessly long lines, etc. Also, what else would be neat to have put into the date file for posterity? Bone::Easy, perhaps?
Thanks for your time!
#!/usr/bin/perl -w ### # The latest version of my diary program ### use strict; use POSIX 'strftime'; # declare the variables my @diary = "/path/to/diary/diary.txt"; my $filename=strftime("/path/to/diary/%m-%d-%Y.entry.txt",localtime); my ($minute, $hour, $day, $month, $year) = (localtime)[1,2,3,4,5]; # format the time properly $month++; $year += 1900; # open the files for writing/appending open FILE, ">>$filename" or die "Can't open file: $!\n"; open DIARY, ">>@diary", or die "Can't open file : $!\n"; # put the time in the diary, time and weather in the date page printf DIARY ("%02d\/%02d\/%04d %02d\:%02d \n", $month, $day, $year, $ +hour, $minute); printf FILE ("%02d\:%02d \n", $hour, $minute); weather(); # write the diary entry print "Go ahead and write. Hit ^D to end. \n"; @diary = <STDIN>; print FILE "@diary \n"; print DIARY "@diary \n"; # close the files close(FILE); close(DIARY); # the weather subroutine sub weather { use Geo::Weather; my $weather = new Geo::Weather; my $current = $weather->get_weather('07060'); print FILE "Temperature in Plainfield, NJ\: $current->{temp} degree +s\n\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: a learning exercise - diary program
by ColonelPanic (Friar) on Jan 27, 2001 at 01:42 UTC | |
Re: a learning exercise - diary program
by Elgon (Curate) on Jan 27, 2001 at 01:11 UTC | |
Re: a learning exercise - diary program
by chromatic (Archbishop) on Jan 27, 2001 at 05:17 UTC | |
by a (Friar) on Jan 27, 2001 at 09:56 UTC | |
($code or die): Re: a learning exercise - diary program
by $code or die (Deacon) on Jan 27, 2001 at 07:44 UTC |