Ok. Maybe I wasnt able to explain the problem. Here it is point by point. I want a particular line from a file, which has the format "Date: DD:MM:YYYY HH:MM:SS", parse it to identify the date part and find the epoch time. Here is what I am trying to do: Lets take the example of the line as "Date: 02.07.2011 16:14:48"

* I read the full date from the file (including the "Date:" which is included in the line) and put it in a scalar variable $array

* Once I get the date in $array, I read the individual numbers. For example, to get the Year, I use the substr function to find the exact start of the year, till the exact end. Here, 22 is the starting point of the year and reading 8 units to read the entire Year. Strangely, it is calculating 8 units for 4 digits.

* I do the same for the others, reading the Month, the day, the Hours, Minutes and Seconds using the substr function. When I print these values, I get the correct output. For $year, I get the 4 digit year, for example 2011. For $month, I get the two digit month value, 07. For $date, I get the two digits, and so on for all others.

* These values are passed on to the DateTime->new function to get the epoch time. This generates an error saying I have entered an undefined value!

I have tried playing around with the scalars, and I am not able to identify where I am wrong.

Corion, I had to put  $year=substr $array[13],22,8 since that is what is giving me the full year (2011).

I even used the Function ParseDate(). When I directly give the ParseDate() a string, like this  ParseDate("02.07.2011 16:14:48");, things work great, but when try the script $time=substr $array[13],22,8; ParseDate($time); I get an error saying the input is undef.

Jethro, when I executed your code using the Dumper, I got the following output: $VAR1 = "\0002\0000\0001\0000"; Would really appreciate if you could explain.

Thanks guys for the help. I hope I have been able to explain my problem. Looking forward to some more help. Thanks

In reply to Re: Not able to ParseDate lines from a file by xpl0it
in thread Not able to ParseDate lines from a file by xpl0it

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.