in reply to I am a beginner in perl,not able to get the output for the following



#!/usr/bin/perl
my @t = localtime(time);
print @t;
  • Comment on Re: I am a beginner in perl,not able to get the output for the following

Replies are listed 'Best First'.
Re^2: I am a beginner in perl,not able to get the output for the following
by madhann (Initiate) on Sep 04, 2007 at 12:11 UTC
    Now it gives me "336174810722460" as output,this should be local time in seconds,how do i calculate the total seconds between local time and sep 6th,6.04 of 2007.

      This sounds to me very much like a XY Problem. Your first question was (rephrased) how to convert some numbers to a timestamp. Now your question seems to be how to subtract the number you got that way from another string. Maybe you can help us improve the answers you get by telling us exactly what you start out with, what you want to have in the end and what you have tried so far?

      Maybe you have two strings that seem to represent timestamps and you want to know the number of seconds between them? Then a convenient solution would be to extract the numbers from these strings and to calculate the epoch times from them, calculate the difference of these epoch times, and then to create a new timestamp-looking-string from those.

      But it's hard for us to guess, even though now we have Acme::ESP.

      The naive way of doing this is by calculating the number of seconds since the epoch using timelocal for both moments and then subtracting the smaller from the bigger. That will give you the difference in seconds between the two moments. However, you may run into problems with Daylight Saving Time and such.

      If you really need to have the exact calculations taking into account different timezones and all kind of "specials", use DateTime.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James