in reply to Getting modification time in perl not working on my MAC

 -M $dir[1]; # tried this, not working.

Non-existent variables don't exist ... makes sense to me

Whatever problem you're trying to solve, use strict 'vars'; will warn you about inventing variable names you havent used yet

Anyway, readdir is the devil, use Path::Tiny, it throws "exceptions" like autodie

use Path::Tiny qw/ path /; my @files = path( $CosMovFolder )->realpath->children(); my @sorted_files = map { $$_[1] } sort { $$a[0] <=> $$b[0] } map { [ -m $_, $_ ] } @files;
  • Comment on Re: Getting modification time in perl not working on my MAC (because i'm a stupid noob)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Getting modification time in perl not working on my MAC
by hary536 (Novice) on Mar 21, 2014 at 16:36 UTC
    Hi, Thanks for your reply. I was copying and pasting the main code out of my file here(omitting the extra comments I have in my file). I had modified variable names in my main code but not in the comments. Though, with all the variables correct, it is still not working. -M command is working if it is between the opendir and closedir lines. If -M is outside anywhere it is not working. I am trying to compare the modification time of the latest modified file against the current time and make some decision if the time difference is more than 30 minutes. Any suggestions? Thanks.
      Correction to my previous statement. -M option works as long as that line is before the sort line. IF I use it after the sort line, it gives that uninitialized message. I don't understand why. Thanks.
        Yeah, because $moviedir[1] is a ".."

      Though, with all the variables correct, it is still not working. -M command is working if it is between the opendir and closedir lines

      Well you have  -M $moviedir[1] and  -M "$CosMovFolder/$moviedir[1]" its the basic stumbling block of readdir that everyone stumbles on .

      readdir is just low level api ... low level api are a pain

      use Path::Tiny its easy

      use Path::Tiny qw/ path /; my @sorted_files = map { $$_[1] } sort { $$a[0] <=> $$b[0] } map { [ $_->stat->mtime, $_ ] } path( $CosMovFolder )->realpath->children();