in reply to Formatting dates
my $epoch=timelocal($sec, $min, $hr, $d, $m, $y);
In the code you gave, you never set $sec, $min, or $hr. Those are uninitialized values and are probably causing your error.Update: Scratch that. You did set them. I must be blind. Update again: I take that back. You aren't setting them and that's the cause of your unitialized variables in Time::Local. The code, my ($sec,$min,$hr) = 0; is incorrect. You could use my ($sec,$min,$hr) = (0,0,0); but that is ugly. Just declare and set them separately.
my $sec = 0; my $min = 0; my $hr = 0;
$y-=1900;
In this case, you don't want to subtract 1900 from your year because the data you are working with is two digit years. Subtracting 1900 from 02 is going to give you -1898. Oops. Because the date is already stored as two digits, you have a y2k problem. Depending on what your date ranges can be, you'll probably have to resort to making an intelligent guess which century that the date occured in. Add 0 or 100 as appropriate and then call timelocal.
Update: Also. . .
my ($d, $m, $y)=split/\//, $i;
That's splitting in the wrong order. Your dates are M/D/Y not D/M/Y. It should be my ($m, $d, $y) = split m!/!, $i; instead.
Update: And one more thing...
($fmt_date[$i])=strftime('%d-%b-%Y', localtime($epoch));
The $fmt_date[$i] part of that line is wrong because $i should contain your original date as it appeared in @dates. You might fix that by putting my $c = 0; somewhere before your loop and changing the $i in that line to $c++. There would be better ways to do the whole thing but that's a quick fix.
-sauoq "My two cents aren't worth a dime.";
|
|---|