Convert 20080928014155 to date time in perl?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brainbox
    New Member
    • Oct 2008
    • 2

    Convert 20080928014155 to date time in perl?

    I have 2 questions:
    1.When I read the number using (\S+) its getting stored as 2.08E13.
    Code I used:
    Code:
    if ($line=~/4_begindt_(\S+)/) {
    print "$1\n"	}
    # $1=2.08E13; instead $1 should contain 20080928014155
    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
    Last edited by numberwhun; Oct 1 '08, 01:25 AM. Reason: Please use code tags
  • Icecrack
    Recognized Expert New Member
    • Sep 2008
    • 174

    #2
    First off Use Code Tags,

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

    3rd, Try:

    Code:
    $a=20080928014155;
    now try this your self we are not a scripting/programing service when you do, paste code with errors or problems.

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      When I do this:

      Code:
      $line = '4_begindt_20080928014155';
      if ($line=~/4_begindt_(\S+)/) {
         print "$1\n";
      }
      the output is: 20080928014155

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by Icecrack
        First off Use Code Tags,

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

        3rd, Try:

        Code:
        $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.

        Comment

        • Icecrack
          Recognized Expert New Member
          • Sep 2008
          • 174

          #5
          Originally posted by KevinADC
          When I do this:

          Code:
          $line = '4_begindt_20080928014155';
          if ($line=~/4_begindt_(\S+)/) {
             print "$1\n";
          }
          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 #
          Last edited by Icecrack; Oct 1 '08, 01:59 AM. Reason: Posted at the same time,

          Comment

          • brainbox
            New Member
            • Oct 2008
            • 2

            #6
            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, ?

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              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

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                Originally posted by brainbox
                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?

                Comment

                Working...