#perl -w use strict; my ($mday, $month, $year, $szBaseFilename, $szFilename, $szSubject) = ""; my $iLoopCount = 0; my $szPath = 'E:\users\dbush\Notes'; (undef, undef, undef, $mday, $month, $year, undef, undef, undef) = localtime(time); $month = $month + 1; $year = $year + 1900; if ($mday < 10) {$mday = "0$mday"} if ($month < 10) {$month = "0$month"} system "title Create today's note"; $szSubject = GetUserInput("Subject"); $szBaseFilename = "$szPath\\$year-$month-$mday"; if ($szSubject eq "") { $szFilename = "$szBaseFilename.txt"; } else { $szFilename = "$szBaseFilename $szSubject.txt"; } while (-e $szFilename) { $iLoopCount++; if ($szSubject eq "") { $szFilename = "$szBaseFilename--$iLoopCount.txt"; } else { $szFilename = "$szBaseFilename--$iLoopCount $szSubject.txt"; } print "Trying $szFilename...\n"; } open hFile, ">$szFilename" or die "Can't open file $szFilename for write: $!\n"; print hFile "$mday/$month/$year\n$szSubject\n\n"; close hFile; system "notepad $szFilename"; exit; ### Supporting functions ### sub GetUserInput { my ($szPrompt, $szDefaultVal, $szValidRegEx) = @_; my $szInput = ""; do { if ($szDefaultVal eq undef) { print $szPrompt.": "; chomp($szInput = ); } else { print "$szPrompt [$szDefaultVal]: "; chomp($szInput = ); if ($szInput eq "") {$szInput = $szDefaultVal;} } } until $szInput =~ /$szValidRegEx/ or $szValidRegEx eq undef; return $szInput; }