strredwolf has asked for the wisdom of the Perl Monks concerning the following question:

Grumble I'm trying to do a date-baised "tempcache" with wsproxy but things are very messy. A section of code (generalized) is:

&sendfile($file) if(-e $file && -s $file && -M $file < 3);
Somehow, it always fails to send a file, but if I remove the -M $file < 3, it works (but buggy, I want it to be able to not send from the cache if a file's anchent.

Am I doing some thing wrong?

--
Perl is intergalactic! WolfSkunks use it!

Replies are listed 'Best First'.
Re: Date checking files for a cache
by chromatic (Archbishop) on Sep 23, 2000 at 23:10 UTC
    If this program is long running, be aware that -M reports file ages based on the time your program started.

    Thus, the results of this snippet are the same, though you might expect otherwise:

    print -M 'temp'; print "\n"; sleep 2; print -M 'temp';

    stat might be better for you.

RE: Date checking files for a cache
by extremely (Priest) on Sep 24, 2000 at 02:53 UTC

    My first thought is why do a '-e' if you are going to do a '-s' too? -s returns false on non-existing files. It has to exist to have a size.

    Do you have an oddball filesystem? Old version of perl? Is the file a symlink?

    Can you rewrite the code like this?

    { my $s= -s $file; my $m= -M $file; if ($s and $m > 3) { &sendfile($file) # does it return a checkable value? } else { die "file: $file\nsize: $s, time: $M\n"; } }

    Or if you can, debug mode is your friend. The code you sent "WorksForMe", with or without the '-e'.

    --
    $you = new YOU;
    honk() if $you->love(perl)

      Hmmm... somehow that's working. Strange. Thanks.

      --
      &$WolfSkunks({use Perl;}); do {$you};

Re: Date checking files for a cache
by merlyn (Sage) on Sep 23, 2000 at 23:02 UTC
    Nothing looks wrong with the code you posted. Must be somewhere else.

    -- Randal L. Schwartz, Perl hacker


    Update: well, yeah, and the "somewhere else" is that perhaps the program is long-running, or something no one has thought of. {grin}
      With this program, it only pulls the file, forwards it, and promptly dies. The code above execs almost immedately before I do any network lookups. Strange.

      --
      Perl is intergalactic! WolfSkunks use it!