in reply to A Tied Dated Hash?

Why not just use the timestamp on the tied hash file before you open it. Then if the hash file timestamp isn't the current date then empty the hash first thing after tieing to it.

Replies are listed 'Best First'.
RE: Re: A Tied Dated Hash?
by princepawn (Parson) on Oct 18, 2000 at 21:33 UTC
  • What module should I use for this purpose?
  • How do you get the timestamp of a file?

      UPDATE In the interests of having a workable skeleton that takes account of Fastolfe's point below about -M not being time-compatible, this code has been modified from its original form

      You could use the builtin -M test, to find out the last time the file was modified (see Fastolfe's comment below for why this might not be the best way to get the time!).

      Here's something skeletal you could build on.

      my @today = (localtime)[3..5]; # gets day, month-1, and year my $last_modified = (stat($tied_hash_file))[9]; # grab the modificatio +n time my @last_modified_date = (localtime($last_modified))[3..5]; # search perlfaq4 (I think) for the compare_array routine! # ... tie the hash, then %tied_hash = () unless compare_array(\@today, \@last_modified_date);

      Philosophy can be made out of anything -- or less

        Note that -M does not work with time-compatible values. Instead, it returns the age of the file in days since the script was started. Likewise with the -A and -C tests. This is most likely not what you want. The 10th field of a stat call will provide you with the last modification time of the file in seconds since the epoch (time-compatible).
      I don't know what the best module to use here, but stat will give you information about files. See the perlfunc manpage.