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

Thanks folks, playing with all those ideas now :-)
  • Comment on Efficient multiplatform directory polling

Replies are listed 'Best First'.
Re: Efficient multiplatform directory polling
by moritz (Cardinal) on Jun 14, 2009 at 10:51 UTC
Re: Efficient multiplatform directory polling
by sflitman (Hermit) on Jun 14, 2009 at 11:14 UTC
    I think the most cross-platform portable way to do this is polling, but glob and stat are actually pretty quick:

    sub getNewestFile { my $dir=shift; my @files=glob "$dir/*"; my %mtimes; map { $mtimes{$_}=(stat $_)[9] } @files; @files=sort { $mtimes{$b}<=>$mtimes{$a} } keys %mtimes; $files[0]; }

    See what you think, burden on your system should be minimal if you do it less than once every second.

    HTH,
    SSF