<?xml version="1.0" encoding="windows-1252"?>
<node id="54624" title="a learning exercise - diary program" created="2001-01-26 18:57:04" updated="2005-07-19 14:08:39">
<type id="115">
perlquestion</type>
<author id="39362">
ailie</author>
<data>
<field name="doctext">
&lt;p&gt;Greetings, Monks. If you'd be willing to lend me some of your time and expertise I would appreciate it.
&lt;p&gt;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.
&lt;p&gt;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.
&lt;p&gt;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?
&lt;p&gt;Thanks for your time!

&lt;p&gt;
&lt;pre&gt;
&lt;code&gt;
#!/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, "&gt;&gt;$filename" or die "Can't open file: $!\n";
open DIARY, "&gt;&gt;@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 = &lt;STDIN&gt;;
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-&gt;get_weather('07060');
   print FILE "Temperature in Plainfield, NJ\: $current-&gt;{temp} degrees\n\n";
}
&lt;/code&gt;
&lt;/pre&gt;</field>
</data>
</node>
