in reply to Age of dir in UNIX

Read your if statement, you essentially say that if the last modified time of the directory is greater than 2 minutes ago, print "Not modified within last 2 minute". This is clearly not what you want to do. Here is a slightly tidied up version, see also File::stat which is a core module, and Basic debugging checklist.

#!/bin/usr/perl use strict; use warnings; my $modified_within = 2 * 60; my $InputDir = "/home/marto/derpderp"; my $LastModified = (stat($InputDir))[9]; my $CurrentTime = time; if ( $LastModified > ($CurrentTime - $modified_within) ){ print "Modified in last 2 minutes\n"; }else{ print "Not Modified in last 2 minutes\n"; }

Replies are listed 'Best First'.
Re^2: Age of dir in UNIX
by kaka_2 (Sexton) on Dec 05, 2013 at 11:08 UTC

    Thank You for your response. This does not work as well. it is always goes into else part of IF

      I tested this on debian, creating new files/directories, running the code, waiting for a few minutes and running the code again. It worked every time. Try adding some debug statements, perhaps the values aren't what you expect them to be.