perl script to generate a list of Julian day/day of year dates, given start and end.

I discovered myself on a unix system with a 'date' utility that only accepts the -u and + parameters, a fairly basic perl install, and lots of archives that are listed by the "Julian day" (day of year) date.

I put together a perl script using the functions I had at my disposal. The script below makes some allowance for a few different formats, but not nearly as much as Date::Manip would have given me. Feedback appreciated.

#!/usr/bin/perl
 
use Time::Local;
use Getopt::Long;
use strict;
 
 
 
sub getJJJFromParameter
{
	my $dateString = shift; 
	our $mm;
	our $dd;
	our $yyyy;
 
	if($dateString =~ m/d{1,2}/d{1,2}/d{2,4}/) {
		($mm, $dd, $yyyy) = split(///, $dateString);
	} elsif ($dateString =~ m/d{2,4}-d{1,2}-d{1,2}/) {
		($yyyy, $mm, $dd) = split(/-/, $dateString);
	} elsif ($dateString =~ m/d{1,2}-d{1,2}-d{2,4}/) {
		($mm, $dd, $yyyy) = split(/-/, $dateString);
	}
	$yyyy %= 100;
	$yyyy += 100;
 
	my @dt = localtime(timelocal(0,0,0,$dd,$mm-1,$yyyy));
 
	return($dt[7]+1);
}
 
# main script
 
my $startDate='';
my $endDate='';
my $startJJJ = 0;
my $endJJJ = 0;
 
GetOptions('start=s' => $startDate, 'end=s' => $endDate);
 
if ($startDate == '') {
	exit;	
} else {
	$startJJJ = getJJJFromParameter($startDate); 
}
if ($endDate != '') {
	$endJJJ = getJJJFromParameter($endDate); 
} else {
	$endJJJ = $startJJJ;
}
 
my $jjj;
 
printf "%03d to %03dn", $startJJJ, $endJJJ;
 
for ($jjj=$startJJJ; $jjj <= $endJJJ; $jjj++) {
	printf("%03d ", $jjj);
}

This kid knew enough to be dangerous.

Running this old code, which was probably not actually turned in for anything, through the gcc compiler alone showed that there was a glaring error that would have been exposed on the the first run.

Beyond the initial compiler warnings, there are the ALL CAPS variables, the while loops used as pure for loops...

 
#include "stdio.h"
main()
{
 
    int rows,columns,ROW, COLUMN;
    scanf("%d %d",ROW,COLUMN);
    rows = 0;
    columns = 0;
    while(columns++ < COLUMN)
        printf("xdb");
    printf("n");
    rows += 1;
    while(rows++ < (ROW - 2)){
        columns = 0;
        printf("xdb");
        while(columns++ < (COLUMN - 2)){
            printf(" ");
            }
        printf("xdbn");
        }
    columns = 0;
    while(columns++ < COLUMN) {
        printf("xdb");
        }
 
 
}