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. ThanksIn 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |