mr.nick has asked for the wisdom of the Perl Monks concerning the following question:
I tried to be clever about this and got the following:
What I wanted to do is get rid of the for my $x (@fts) construct and somehow combine it with the map statement (getting rid of the @fts variable at the same time). I had tried something likesub chk_snapshot { my $dir=shift; return unless -f "$dir/.snapshot"; my $ft=(stat("$dir/.snapshot"))[9]; my @fts=map { (stat($_))[9] } grep -f $_,($0,glob "$dir/*"); ## return if .snapshot is older than any for my $x (@fts) { return if $x > $ft; } warn "snapshot is newer"; snarf_file("$dir/.snapshot"); }
But that didn't work because map returns (in this case) an array of undef's, not an empty array; so the return in that construct is always executed.return if map { (stat($_))[9] > $ft } grep -f $_,($0,glob "$dir/*");
So my question is, does anyone know how to achieve the goal of gathering the filestamps AND checking them in a single line (like my non-functional return if map ...)?
TIA!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Clever timestamp comparison
by japhy (Canon) on May 06, 2001 at 00:33 UTC | |
|
Re: Clever timestamp comparison
by Beatnik (Parson) on May 06, 2001 at 01:38 UTC | |
|
Re: Clever timestamp comparison
by boo_radley (Parson) on May 06, 2001 at 00:35 UTC |