in reply to Re: method of ID'ing
in thread method of ID'ing

Hmmm... how about using Time::HiRes to increase precision of $^T (in reasonable cases of course)?!

$^T is set before Time::HiRes can be loaded, so it won't make a difference. $^T is not a magic variable that issues time, it is set when the interpreter starts (which can cause a lot of trouble when running under mod_perl, irssi, or any other long term perl embedder).

Don't use $^T for IDing purposes, use time instead. To update existing scripts (but it might break some that depend on $^T to not change), you could use:

package Tie::Time; use Carp; use strict; sub TIESCALAR { bless \my $dummy, shift } sub STORE { croak 'Cannot set time this way' } sub FETCH { time } =head1 NAME Tie::Time - Have a scalar return the current time() =head1 SYNOPSIS tie my $time, 'Tie::Time'; # New variable tie $^T, 'Tie::Time'; # Override existing $^T =head1 DESCRIPTION Guess :) =head1 URL http://perlmonks.org/?node_id=158912 =cut

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: method of ID'ing
by particle (Vicar) on Apr 14, 2002 at 13:27 UTC
    how about adding require Tie::Scalar, and throwing this in the code catacombs? this is a nice, simple answer to retrieving the current time.

    ~Particle ;Þ

      how about adding require Tie::Scalar

      There's not much point in having a base class if you override all methods :) Well, I don't use new() and DESTROY(), but those are rather optional...

      and throwing this in the code catacombs? this is a nice, simple answer to retrieving the current time.

      It doesn't belong there. This use should not be encouraged, just use time instead. This was a one-minute hack, typed in my browser. If you think it belongs there, go ahead, there is no copyright at all :)

      While you're at it, create these as well:

      package Tie::Print; require Tie::Scalar; our @ISA = ('Tie::StdScalar'); sub STORE { print pop } package Tie::Localtime::Scalar; require Tie::Scalar; our @ISA = ('Tie::StdScalar'); sub FETCH { return scalar localtime } etcetera
      Have a look at perlfunc for more ideas. Or just use a one-fits all tie:
      package Tie::Scalar::Miscellaneous; use Carp; use strict; sub TIESCALAR { my ($class, %functions) = @_; $_ ||= q(croak 'Not implemented') for @functions{qw/store fetch/}; $_ = eval "sub { $_ ( \@_ ) }" for @functions{qw/store fetch/}; bless \%functions, $class; } sub STORE { shift->{store}->(pop) } sub FETCH { shift->{fetch}->(); }
      Which can be used like:
      tie my $printer, 'Tie::Scalar::Miscellaneous', store => 'print'; $printer = "Hello, world!\n";
      No, I'm not being serious.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        package Tie::Scalar::Miscellaneous;

        ha! i love it. who needs functions when everything can be a variable assignment?

        by the way, i agree that time should be used instead. i thought perhaps this would be a good fit for something like gav^ or tachyon's solutions (posted above), although it's probably easier to maintain as a function rather than a tied scalar.

        ~Particle ;Þ

Re: Re: Re: method of ID'ing
by tmiklas (Hermit) on Apr 14, 2002 at 17:09 UTC
    As i see your answers always get to the point... ;-)
    I've never used $^T for this task - always time(). Besides for some time i use unique_id provided with Apache ;-) and from this point have almost nothing to worry about ;-).

    Greetz, Tom.