http://qs321.pair.com?node_id=1230184


in reply to Intermittent bug in module: File not getting deleted as expected

OK, I'm beginning to think this is some kind of bug with -M, or the OS (happening on Linux and Mac, though). If I add a delay into the test script of a whole 5 seconds, the file age will sometimes be reported as a negative value -1.15740740740741e-05.

I think I'm going to solve this by simply changing it from -M $file > 0 to -M $file > -1 as suggested above.

Thanks!

But curious to know why it's reporting a negative value at all.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^2: Intermittent bug in module: File not getting deleted as expected
by tybalt89 (Monsignor) on Feb 19, 2019 at 18:58 UTC

    If I understand your problem (which is very iffy).

    -M measures from start of program (kept in $^T). sleep() just make things worse. Adjust start of program. $^T = time; at or after creation of file will fix;

      - M reports the age of the file in days.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        From perldoc -f -M

        -M  Script start time minus file modification time, in days.

Re^2: Intermittent bug in module: File not getting deleted as expected
by stevieb (Canon) on Feb 19, 2019 at 18:51 UTC

    I think you mean:

    if (-M $file > -2)

    In other words, -1.15 is less than -1, not greater than ;)

    Either way, it would be nice to find out exactly what's happening here. I'll play around later. If you happen to find anything, post back please.

      I think we have the answer for this behavior. See the comment further down and this. It seems that the time the script starts is factored into the age of the file. Still trying to wrap my head around it, though. Seems weird.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

      Well, it's to the power of 10^-5, so -.000015.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Ahhh, of course. I overlooked that part of your number :)