in reply to To count number of files created yesterday in a directory

Using Time::Piece and Time::Seconds, (in the core since perl version 5.9.5), you can get the count of files created yesterday with the code below.
#!/usr/bin/perl use strict; use warnings; use Time::Piece; use Time::Seconds; my $t = localtime() - ONE_DAY; # yesterday my $count = grep {$t->ymd eq localtime( (stat)[9] )->ymd} glob "*.*";
(I was not able to use the code below, even though the documentation for Time::Piece says '==' is possible.)

my $count = grep {$t == localtime( (stat)[9] )} glob "*.*";

Update: Of course it wouldn't work as it's comparing 'ymdhms' rather than 'ymd'.

Replies are listed 'Best First'.
Re^2: To count number of files created yesterday in a directory
by hippo (Archbishop) on Feb 04, 2017 at 11:18 UTC
    glob "*.*";

    Note that the above glob will only match files/dirs containing a dot. If memory serves, this is a Microsoftism because in their world a simple glob "*" doesn't match all entries like it would on other platforms.

    Luckily there are things like File::Glob to help with making such actions platform-independent.

      Hi hippo,

      a simple glob "*" doesn't match all entries like it would on other platforms

      At least on Linux, glob "*" skips entries beginning with a dot, to get those you need glob ".* *".

      Regards,
      -- Hauke D