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.";

In reply to Re: Formatting dates by sauoq
in thread Formatting dates by cajun

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.