in reply to Re^2: Dynamically searching subdirs with titles based on year,month, and date
in thread Dynamically searching subdirs with titles based on year,month, and date

I get
Usage: POSIX::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) at dirtt.pl line 20.
when I run the script
You get that error if you call strftime without enough argument.
  • Comment on Re^3: Dynamically searching subdirs with titles based on year,month, and date

Replies are listed 'Best First'.
Re^4: Dynamically searching subdirs with titles based on year,month, and date
by hbm (Hermit) on Jan 16, 2009 at 23:59 UTC
    It's squawking about your strftime. In a new script, try just this:
    use strict; use warnings; use POSIX qw(strftime); my ($m, $y) = strftime ("%b %Y", localtime) =~ m|(\S+)\s(\S+)|; print "$m $y";

    That should get you further...

    Update:

    • For monthly cron's, you might want to cron on the first of the next month and simply get "yesterday's" date. That way you don't have to fight the 28th/29th/30th/31st thing in crontab. And it may save you from checking the files' mtimes, if the application will have begun writing to a new monthly directory. And if you don't mind backticking, GNU date has this slick feature: date --date '1 day ago' '+%b %Y'.
    • You'll probably want to allow yourself to pass in the month and year, or default to the programmatic values. Backups have a way of needing a retro-run.
      Thanks, that has moved me closer to the finish line.
      Hello,
      use strict; use warnings; use POSIX qw(strftime); my ($m, $y) = strftime ("%b %Y", localtime) =~ m|(\S+)\s(\S+)|; print "$m $y";
      when used in:
      #!/usr/bin/perl use strict; use warnings; use POSIX qw(strftime); my $Results = strftime ("Results %m-%d-%y", localtime) =~ m|(\S+)\s(\S ++)|; print "$Results\n"; #my ($m, $y) = strftime ("%b %Y", localtime) =~ m|(\S+)\s(\S+)|; #print "$m $y\n"; my $root='/home/mgavi/testdir1'; my $seqdir = "/home/mgavi/testdir2/SeqAssembly"; opendir (my $dh, $root); #chdir($newdir); my @files=readdir $dh; for my $f (@files){ my $mod_time=-M $root."/".$f; #skip unless modification date is less than one day ago next if $f eq '.' || $f eq '..' || $mod_time > 1.0; print $f,"\t",$mod_time,"\t",ctime(stat($root."/".$f)->mtime),"\n" +; copy("$f","$seqdir"); } closedir $dh;

      returns:
      1

      I am looking for "Results 01-16-9-09A" to be returned because
      that is the most recent dir in "JAN 2009" directory.