#!/usr/bin/perl # simple timesheet generator # step 1. Get the start date for the week use Date::Calc qw( Today Monday_of_Week Week_of_Year ); ($year,$month,$day) = Today(); ($year,$month,$day) = Monday_of_Week(Week_of_Year($year,$month,$day)); # step 2. See if this week's timesheet exists, if not, I'll create it unless (-e "$day-$month-$year.txt") { open(TIMESHEET,">$day-$month-$year.txt") || die("Cannot Open File"); print TIMESHEET ("Timesheet for week commencing $day-$month-$year\n"); } #If it does exist, we need to open it, for appending open(TIMESHEET,">>$day-$month-$year.txt") || die("Cannot Open File"); #Now, we present the user with his timesheet options. Start shift, end shift, off, hols & sick... print "\n"; print "To start shift, push 1...\n"; print "To end shift, push 2...\n"; print "Off? push 3...\n"; print "Sick? push 4...\n"; print "Holiday? push 5...\n"; #get the times and 'tings, to use in a bit. ($wkday,$month,$day,$time,$year) = split(/\s+/, localtime); $dayname = substr((localtime ()), 0, 3); # finds day (three char code- mon, tue etc.) from localtime chomp ($select = ); #get the choice, then ye olde if statements for the printing if ($select == 1) { print TIMESHEET ("$dayname $time to "); } elsif ($select == 2) { print TIMESHEET ("$time \n"); } elsif ($select == 3) { print TIMESHEET ("$dayname off\n"); } elsif ($select == 4) { print TIMESHEET ("$dayname sick\n"); } elsif ($select == 5) { print TIMESHEET ("$dayname holiday\n"); }