Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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"; }

In reply to a learning exercise - diary program by ailie

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2015-10-04 06:24 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (99 votes), past polls