in reply to more on tying localtime
#!/usr/bin/perl -w use strict; package TieTimeArray; sub TIEARRAY { bless [], shift } sub FETCH { (localtime)[$_[1]] } sub FETCHSIZE { 9 } package main; my @now; tie (@now, "TieTimeArray"); while (1) { local $"=' '; print "@now\n"; sleep 1; }
It compile and works (sort of). Indeed we hit a problem with the array tie design. you can't ask array content as a whole, so we ask local time for each element of the array. We hit the problem that gray codes are designed to avoid (pointer pending) Suppose that thru one defererence of @now, we ask time at 3:00 59.99999 sec to get the seconds, than again a jiffy later at 3:01 0 sec to get the minutes. We will give as a result 3:01 59 sec. Not good when it is instead 3:01 0 sec
So this is not really a good approach. So consider it only as a rather silly example of array tie code. If you want to tie here, tie to scalar.
-- stefp
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: more on tying localtime
by blueflashlight (Pilgrim) on Oct 02, 2001 at 07:16 UTC |