Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found