By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

Convert 20080928014155 to date time in perl?

P: 2
I have 2 questions:
1.When I read the number using (\S+) its getting stored as 2.08E13.
Code I used:
Expand|Select|Wrap|Line Numbers
  1. if ($line=~/4_begindt_(\S+)/) {
  2. print "$1\n"    }
  3. # $1=2.08E13; instead $1 should contain 20080928014155
  4.  
How to read and store a 15digit number in perl?

2.Once I store the number how do I convert to date and time?
like 09/28/2008 01:41:55

Please let me know
Oct 1 '08 #1
Share this Question
Share on Google+
7 Replies


Icecrack
Expert 100+
P: 174
First off Use Code Tags,

Second don't store var's as $0 - $9 this is perl Special Var's

3rd, Try:

Expand|Select|Wrap|Line Numbers
  1. $a=20080928014155;
now try this your self we are not a scripting/programing service when you do, paste code with errors or problems.
Oct 1 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
When I do this:

Expand|Select|Wrap|Line Numbers
  1. $line = '4_begindt_20080928014155';
  2. if ($line=~/4_begindt_(\S+)/) {
  3.    print "$1\n";
  4. }
the output is: 20080928014155
Oct 1 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
First off Use Code Tags,

Second don't store var's as $0 - $9 this is perl Special Var's

3rd, Try:

Expand|Select|Wrap|Line Numbers
  1. $a=20080928014155;
now try this your self we are not a scripting/programing service when you do, paste code with errors or problems.
I think you misunderstood. He is not using $1 as a private variable but as the capturing group from the regexp, he just added the "=" symbol to show what its value is and what he wants it to be.
Oct 1 '08 #4

Icecrack
Expert 100+
P: 174
When I do this:

Expand|Select|Wrap|Line Numbers
  1. $line = '4_begindt_20080928014155';
  2. if ($line=~/4_begindt_(\S+)/) {
  3.    print "$1\n";
  4. }
the output is: 20080928014155

that would be correct because of the reg exp the $1 prints first of the last reg exp matched.

what OS are you using as well?


Note: yeah just seen that. because of the non code tags i missed the #
Oct 1 '08 #5

P: 2
I am using Windows.
Thats true I am capturing the whole number into $1 using regex.
Should code tags be used for capturing large numbers using regex, ?
Oct 1 '08 #6

numberwhun
Expert Mod 2.5K+
P: 3,503
To convert the string of numbers into the format you want, you will probably have to look at one of the data modules on CPAN, such as this one. But there are a bunch of others depending on what you want to do.

Regards,

Jeff
Oct 1 '08 #7

KevinADC
Expert 2.5K+
P: 4,059
I am using Windows.
Thats true I am capturing the whole number into $1 using regex.
Should code tags be used for capturing large numbers using regex, ?
The "code" tags is for posting code on this forum, nothing to do with perl. I am also using my old W98 server with activeperl 5.8.8 installed and I do not get the output you are getting. Is there more to your code?
Oct 1 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.