Loading ...
Sorry, an error occurred while loading the content.
 

RE: [PBML] Perl static var -- and a time warp...

Expand Messages
  • Charles K. Clarkson
    ... That was Randall, not Larry that proposed it. ... This is not a time warp problem. It is a time zone problem. You probably have your locale set to one hour
    Message 1 of 11 , Mar 9, 2004
      Allan Dystrup <allan_dystrup@...> wrote:
      :
      : This is (scope wise) imho not as elegant as many other language
      : features in perl, but it does solve the issue; A more neat solution
      : would prob. be (as suggested by Larry) to define this stuff in a
      : separate package scope with the static var in a BEGIN initializer
      : block (possibly in a seperate module). -- I like that idea.

      That was Randall, not Larry that proposed it.


      : And now to something completely different... A time warp!
      : The algorithm for the timeDiff above is... not very cool.

      This is not a time warp problem. It is a time zone problem.
      You probably have your locale set to one hour before Greenwich
      Mean Time. Any times calculated /below/ 1 hour will show the
      extra hour. The better solution is to use Date::Calc, but here
      is another diffTime() using gmtime():

      sub timeDiff {
      return sprintf "%s:%s:%s", ( gmtime time - $sT )[ 0 .. 2 ];
      }


      HTH,

      Charles K. Clarkson
      --
      Mobile Homes Specialist
      254 968-8328
    • Charles K. Clarkson
      ... Whoopsie! That should be: return sprintf %s:%s:%s , ( gmtime time - $sT )[ 2, 1, 0 ]; Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328
      Message 2 of 11 , Mar 9, 2004
        Charles K. Clarkson <cclarkson@...> wrote:
        :
        : sub timeDiff {
        : return sprintf "%s:%s:%s", ( gmtime time - $sT )[ 0 .. 2 ];
        : }

        Whoopsie!

        That should be:

        return sprintf "%s:%s:%s", ( gmtime time - $sT )[ 2, 1, 0 ];


        Charles K. Clarkson
        --
        Mobile Homes Specialist
        254 968-8328
      • merlyn@stonehenge.com
        ... Charles Allan Dystrup wrote: Charles : Charles : This is (scope wise) imho not as elegant as many other language Charles :
        Message 3 of 11 , Mar 9, 2004
          >>>>> "Charles" == Charles K Clarkson <cclarkson@...> writes:

          Charles> Allan Dystrup <allan_dystrup@...> wrote:
          Charles> :
          Charles> : This is (scope wise) imho not as elegant as many other language
          Charles> : features in perl, but it does solve the issue; A more neat solution
          Charles> : would prob. be (as suggested by Larry) to define this stuff in a
          Charles> : separate package scope with the static var in a BEGIN initializer
          Charles> : block (possibly in a seperate module). -- I like that idea.

          Charles> That was Randall, not Larry that proposed it.

          I presume you're talking about someone else (even counting the
          spelling being off), because I didn't suggest anything with a package
          scope. All of my variables were "my" variables. :)

          print "Just another Perl hacker,"

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
          See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
        Your message has been successfully submitted and would be delivered to recipients shortly.